Commit 37c8e14e authored by Hubert Chathi's avatar Hubert Chathi
Browse files

make functions const where possible

parent 7263c422
Pipeline #6467 failed with stages
in 2 minutes and 34 seconds
...@@ -49,7 +49,7 @@ struct Account { ...@@ -49,7 +49,7 @@ struct Account {
OlmErrorCode last_error; OlmErrorCode last_error;
/** Number of random bytes needed to create a new account */ /** Number of random bytes needed to create a new account */
std::size_t new_account_random_length(); std::size_t new_account_random_length() const;
/** Create a new account. Returns std::size_t(-1) on error. If the number of /** Create a new account. Returns std::size_t(-1) on error. If the number of
* random bytes is too small then last_error will be NOT_ENOUGH_RANDOM */ * random bytes is too small then last_error will be NOT_ENOUGH_RANDOM */
...@@ -58,7 +58,7 @@ struct Account { ...@@ -58,7 +58,7 @@ struct Account {
); );
/** Number of bytes needed to output the identity keys for this account */ /** Number of bytes needed to output the identity keys for this account */
std::size_t get_identity_json_length(); std::size_t get_identity_json_length() const;
/** Output the identity keys for this account as JSON in the following /** Output the identity keys for this account as JSON in the following
* format: * format:
...@@ -77,7 +77,7 @@ struct Account { ...@@ -77,7 +77,7 @@ struct Account {
/** /**
* The length of an ed25519 signature in bytes. * The length of an ed25519 signature in bytes.
*/ */
std::size_t signature_length(); std::size_t signature_length() const;
/** /**
* Signs a message with the ed25519 key for this account. * Signs a message with the ed25519 key for this account.
...@@ -88,7 +88,7 @@ struct Account { ...@@ -88,7 +88,7 @@ struct Account {
); );
/** Number of bytes needed to output the one time keys for this account */ /** Number of bytes needed to output the one time keys for this account */
std::size_t get_one_time_keys_json_length(); std::size_t get_one_time_keys_json_length() const;
/** Output the one time keys that haven't been published yet as JSON: /** Output the one time keys that haven't been published yet as JSON:
* *
...@@ -111,13 +111,13 @@ struct Account { ...@@ -111,13 +111,13 @@ struct Account {
std::size_t mark_keys_as_published(); std::size_t mark_keys_as_published();
/** The largest number of one time keys this account can store. */ /** The largest number of one time keys this account can store. */
std::size_t max_number_of_one_time_keys(); std::size_t max_number_of_one_time_keys() const;
/** The number of random bytes needed to generate a given number of new one /** The number of random bytes needed to generate a given number of new one
* time keys. */ * time keys. */
std::size_t generate_one_time_keys_random_length( std::size_t generate_one_time_keys_random_length(
std::size_t number_of_keys std::size_t number_of_keys
); ) const;
/** Generates a number of new one time keys. If the total number of keys /** Generates a number of new one time keys. If the total number of keys
* stored by this account exceeds max_number_of_one_time_keys() then the * stored by this account exceeds max_number_of_one_time_keys() then the
...@@ -129,7 +129,7 @@ struct Account { ...@@ -129,7 +129,7 @@ struct Account {
); );
/** The number of random bytes needed to generate a fallback key. */ /** The number of random bytes needed to generate a fallback key. */
std::size_t generate_fallback_key_random_length(); std::size_t generate_fallback_key_random_length() const;
/** Generates a new fallback key. Returns std::size_t(-1) on error. If the /** Generates a new fallback key. Returns std::size_t(-1) on error. If the
* number of random bytes is too small then last_error will be * number of random bytes is too small then last_error will be
...@@ -139,7 +139,7 @@ struct Account { ...@@ -139,7 +139,7 @@ struct Account {
); );
/** Number of bytes needed to output the one time keys for this account */ /** Number of bytes needed to output the one time keys for this account */
std::size_t get_fallback_key_json_length(); std::size_t get_fallback_key_json_length() const;
/** Output the fallback key as JSON: /** Output the fallback key as JSON:
* *
......
...@@ -119,12 +119,12 @@ size_t olm_clear_utility( ...@@ -119,12 +119,12 @@ size_t olm_clear_utility(
/** Returns the number of bytes needed to store an account */ /** Returns the number of bytes needed to store an account */
size_t olm_pickle_account_length( size_t olm_pickle_account_length(
OlmAccount * account const OlmAccount * account
); );
/** Returns the number of bytes needed to store a session */ /** Returns the number of bytes needed to store a session */
size_t olm_pickle_session_length( size_t olm_pickle_session_length(
OlmSession * session const OlmSession * session
); );
/** Stores an account as a base64 string. Encrypts the account using the /** Stores an account as a base64 string. Encrypts the account using the
...@@ -175,7 +175,7 @@ size_t olm_unpickle_session( ...@@ -175,7 +175,7 @@ size_t olm_unpickle_session(
/** The number of random bytes needed to create an account.*/ /** The number of random bytes needed to create an account.*/
size_t olm_create_account_random_length( size_t olm_create_account_random_length(
OlmAccount * account const OlmAccount * account
); );
/** Creates a new account. Returns olm_error() on failure. If there weren't /** Creates a new account. Returns olm_error() on failure. If there weren't
...@@ -188,7 +188,7 @@ size_t olm_create_account( ...@@ -188,7 +188,7 @@ size_t olm_create_account(
/** The size of the output buffer needed to hold the identity keys */ /** The size of the output buffer needed to hold the identity keys */
size_t olm_account_identity_keys_length( size_t olm_account_identity_keys_length(
OlmAccount * account const OlmAccount * account
); );
/** Writes the public parts of the identity keys for the account into the /** Writes the public parts of the identity keys for the account into the
...@@ -203,7 +203,7 @@ size_t olm_account_identity_keys( ...@@ -203,7 +203,7 @@ size_t olm_account_identity_keys(
/** The length of an ed25519 signature encoded as base64. */ /** The length of an ed25519 signature encoded as base64. */
size_t olm_account_signature_length( size_t olm_account_signature_length(
OlmAccount * account const OlmAccount * account
); );
/** Signs a message with the ed25519 key for this account. Returns olm_error() /** Signs a message with the ed25519 key for this account. Returns olm_error()
...@@ -217,7 +217,7 @@ size_t olm_account_sign( ...@@ -217,7 +217,7 @@ size_t olm_account_sign(
/** The size of the output buffer needed to hold the one time keys */ /** The size of the output buffer needed to hold the one time keys */
size_t olm_account_one_time_keys_length( size_t olm_account_one_time_keys_length(
OlmAccount * account const OlmAccount * account
); );
/** Writes the public parts of the unpublished one time keys for the account /** Writes the public parts of the unpublished one time keys for the account
...@@ -250,13 +250,13 @@ size_t olm_account_mark_keys_as_published( ...@@ -250,13 +250,13 @@ size_t olm_account_mark_keys_as_published(
/** The largest number of one time keys this account can store. */ /** The largest number of one time keys this account can store. */
size_t olm_account_max_number_of_one_time_keys( size_t olm_account_max_number_of_one_time_keys(
OlmAccount * account const OlmAccount * account
); );
/** The number of random bytes needed to generate a given number of new one /** The number of random bytes needed to generate a given number of new one
* time keys. */ * time keys. */
size_t olm_account_generate_one_time_keys_random_length( size_t olm_account_generate_one_time_keys_random_length(
OlmAccount * account, const OlmAccount * account,
size_t number_of_keys size_t number_of_keys
); );
...@@ -272,7 +272,7 @@ size_t olm_account_generate_one_time_keys( ...@@ -272,7 +272,7 @@ size_t olm_account_generate_one_time_keys(
/** The number of random bytes needed to generate a fallback key. */ /** The number of random bytes needed to generate a fallback key. */
size_t olm_account_generate_fallback_key_random_length( size_t olm_account_generate_fallback_key_random_length(
OlmAccount * account const OlmAccount * account
); );
/** Generates a new fallback key. Only one previous fallback key is /** Generates a new fallback key. Only one previous fallback key is
...@@ -286,7 +286,7 @@ size_t olm_account_generate_fallback_key( ...@@ -286,7 +286,7 @@ size_t olm_account_generate_fallback_key(
/** The number of bytes needed to hold the fallback key as returned by /** The number of bytes needed to hold the fallback key as returned by
* olm_account_fallback_key. */ * olm_account_fallback_key. */
size_t olm_account_fallback_key_length( size_t olm_account_fallback_key_length(
OlmAccount * account const OlmAccount * account
); );
size_t olm_account_fallback_key( size_t olm_account_fallback_key(
...@@ -297,7 +297,7 @@ size_t olm_account_fallback_key( ...@@ -297,7 +297,7 @@ size_t olm_account_fallback_key(
/** The number of random bytes needed to create an outbound session */ /** The number of random bytes needed to create an outbound session */
size_t olm_create_outbound_session_random_length( size_t olm_create_outbound_session_random_length(
OlmSession * session const OlmSession * session
); );
/** Creates a new out-bound session for sending messages to a given identity_key /** Creates a new out-bound session for sending messages to a given identity_key
...@@ -339,7 +339,7 @@ size_t olm_create_inbound_session_from( ...@@ -339,7 +339,7 @@ size_t olm_create_inbound_session_from(
/** The length of the buffer needed to return the id for this session. */ /** The length of the buffer needed to return the id for this session. */
size_t olm_session_id_length( size_t olm_session_id_length(
OlmSession * session const OlmSession * session
); );
/** An identifier for this session. Will be the same for both ends of the /** An identifier for this session. Will be the same for both ends of the
...@@ -351,7 +351,7 @@ size_t olm_session_id( ...@@ -351,7 +351,7 @@ size_t olm_session_id(
); );
int olm_session_has_received_message( int olm_session_has_received_message(
OlmSession *session const OlmSession *session
); );
/** /**
...@@ -402,18 +402,18 @@ size_t olm_remove_one_time_keys( ...@@ -402,18 +402,18 @@ size_t olm_remove_one_time_keys(
* Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message. * Returns OLM_MESSAGE_TYPE_MESSAGE if the message will be a normal message.
* Returns olm_error on failure. */ * Returns olm_error on failure. */
size_t olm_encrypt_message_type( size_t olm_encrypt_message_type(
OlmSession * session const OlmSession * session
); );
/** The number of random bytes needed to encrypt the next message. */ /** The number of random bytes needed to encrypt the next message. */
size_t olm_encrypt_random_length( size_t olm_encrypt_random_length(
OlmSession * session const OlmSession * session
); );
/** The size of the next message in bytes for the given number of plain-text /** The size of the next message in bytes for the given number of plain-text
* bytes. */ * bytes. */
size_t olm_encrypt_message_length( size_t olm_encrypt_message_length(
OlmSession * session, const OlmSession * session,
size_t plaintext_length size_t plaintext_length
); );
...@@ -464,7 +464,7 @@ size_t olm_decrypt( ...@@ -464,7 +464,7 @@ size_t olm_decrypt(
/** The length of the buffer needed to hold the SHA-256 hash. */ /** The length of the buffer needed to hold the SHA-256 hash. */
size_t olm_sha256_length( size_t olm_sha256_length(
OlmUtility * utility const OlmUtility * utility
); );
/** Calculates the SHA-256 hash of the input and encodes it as base64. If the /** Calculates the SHA-256 hash of the input and encodes it as base64. If the
......
...@@ -62,13 +62,13 @@ size_t olm_pk_encryption_set_recipient_key( ...@@ -62,13 +62,13 @@ size_t olm_pk_encryption_set_recipient_key(
/** Get the length of the ciphertext that will correspond to a plaintext of the /** Get the length of the ciphertext that will correspond to a plaintext of the
* given length. */ * given length. */
size_t olm_pk_ciphertext_length( size_t olm_pk_ciphertext_length(
OlmPkEncryption *encryption, const OlmPkEncryption *encryption,
size_t plaintext_length size_t plaintext_length
); );
/** Get the length of the message authentication code. */ /** Get the length of the message authentication code. */
size_t olm_pk_mac_length( size_t olm_pk_mac_length(
OlmPkEncryption *encryption const OlmPkEncryption *encryption
); );
/** Get the length of a public or ephemeral key */ /** Get the length of a public or ephemeral key */
...@@ -76,7 +76,7 @@ size_t olm_pk_key_length(void); ...@@ -76,7 +76,7 @@ size_t olm_pk_key_length(void);
/** The number of random bytes needed to encrypt a message. */ /** The number of random bytes needed to encrypt a message. */
size_t olm_pk_encrypt_random_length( size_t olm_pk_encrypt_random_length(
OlmPkEncryption *encryption const OlmPkEncryption *encryption
); );
/** Encrypt a plaintext for the recipient set using /** Encrypt a plaintext for the recipient set using
...@@ -160,7 +160,7 @@ size_t olm_pk_generate_key( ...@@ -160,7 +160,7 @@ size_t olm_pk_generate_key(
/** Returns the number of bytes needed to store a decryption object. */ /** Returns the number of bytes needed to store a decryption object. */
size_t olm_pickle_pk_decryption_length( size_t olm_pickle_pk_decryption_length(
OlmPkDecryption * decryption const OlmPkDecryption * decryption
); );
/** Stores decryption object as a base64 string. Encrypts the object using the /** Stores decryption object as a base64 string. Encrypts the object using the
...@@ -191,7 +191,7 @@ size_t olm_unpickle_pk_decryption( ...@@ -191,7 +191,7 @@ size_t olm_unpickle_pk_decryption(
/** Get the length of the plaintext that will correspond to a ciphertext of the /** Get the length of the plaintext that will correspond to a ciphertext of the
* given length. */ * given length. */
size_t olm_pk_max_plaintext_length( size_t olm_pk_max_plaintext_length(
OlmPkDecryption * decryption, const OlmPkDecryption * decryption,
size_t ciphertext_length size_t ciphertext_length
); );
......
...@@ -124,12 +124,12 @@ struct Ratchet { ...@@ -124,12 +124,12 @@ struct Ratchet {
* a given message length. */ * a given message length. */
std::size_t encrypt_output_length( std::size_t encrypt_output_length(
std::size_t plaintext_length std::size_t plaintext_length
); ) const;
/** The number of bytes of random data the encrypt method will need to /** The number of bytes of random data the encrypt method will need to
* encrypt a message. This will be 32 bytes if the session needs to * encrypt a message. This will be 32 bytes if the session needs to
* generate a new ephemeral key, or will be 0 bytes otherwise.*/ * generate a new ephemeral key, or will be 0 bytes otherwise.*/
std::size_t encrypt_random_length(); std::size_t encrypt_random_length() const;
/** Encrypt some plain-text. Returns the length of the encrypted message /** Encrypt some plain-text. Returns the length of the encrypted message
* or std::size_t(-1) on failure. On failure last_error will be set with * or std::size_t(-1) on failure. On failure last_error will be set with
......
...@@ -61,7 +61,7 @@ size_t olm_clear_sas( ...@@ -61,7 +61,7 @@ size_t olm_clear_sas(
/** The number of random bytes needed to create an SAS object. */ /** The number of random bytes needed to create an SAS object. */
size_t olm_create_sas_random_length( size_t olm_create_sas_random_length(
OlmSAS * sas const OlmSAS * sas
); );
/** Creates a new SAS object. /** Creates a new SAS object.
...@@ -81,7 +81,7 @@ size_t olm_create_sas( ...@@ -81,7 +81,7 @@ size_t olm_create_sas(
); );
/** The size of a public key in bytes. */ /** The size of a public key in bytes. */
size_t olm_sas_pubkey_length(OlmSAS * sas); size_t olm_sas_pubkey_length(const OlmSAS * sas);
/** Get the public key for the SAS object. /** Get the public key for the SAS object.
* *
...@@ -119,7 +119,7 @@ size_t olm_sas_set_their_key( ...@@ -119,7 +119,7 @@ size_t olm_sas_set_their_key(
* *
*/ */
int olm_sas_is_their_key_set( int olm_sas_is_their_key_set(
OlmSAS *sas const OlmSAS *sas
); );
/** Generate bytes to use for the short authentication string. /** Generate bytes to use for the short authentication string.
...@@ -144,7 +144,7 @@ size_t olm_sas_generate_bytes( ...@@ -144,7 +144,7 @@ size_t olm_sas_generate_bytes(
/** The size of the message authentication code generated by /** The size of the message authentication code generated by
* olm_sas_calculate_mac()`. */ * olm_sas_calculate_mac()`. */
size_t olm_sas_mac_length( size_t olm_sas_mac_length(
OlmSAS *sas const OlmSAS *sas
); );
/** Generate a message authentication code (MAC) based on the shared secret. /** Generate a message authentication code (MAC) based on the shared secret.
......
...@@ -41,7 +41,7 @@ struct Session { ...@@ -41,7 +41,7 @@ struct Session {
/** The number of random bytes that are needed to create a new outbound /** The number of random bytes that are needed to create a new outbound
* session. This will be 64 bytes since two ephemeral keys are needed. */ * session. This will be 64 bytes since two ephemeral keys are needed. */
std::size_t new_outbound_session_random_length(); std::size_t new_outbound_session_random_length() const;
/** Start a new outbound session. Returns std::size_t(-1) on failure. On /** Start a new outbound session. Returns std::size_t(-1) on failure. On
* failure last_error will be set with an error code. The last_error will be * failure last_error will be set with an error code. The last_error will be
...@@ -64,7 +64,7 @@ struct Session { ...@@ -64,7 +64,7 @@ struct Session {
); );
/** The number of bytes written by session_id() */ /** The number of bytes written by session_id() */
std::size_t session_id_length(); std::size_t session_id_length() const;
/** An identifier for this session. Generated by hashing the public keys /** An identifier for this session. Generated by hashing the public keys
* used to create the session. Returns the length of the session id on * used to create the session. Returns the length of the session id on
...@@ -84,21 +84,21 @@ struct Session { ...@@ -84,21 +84,21 @@ struct Session {
bool matches_inbound_session( bool matches_inbound_session(
_olm_curve25519_public_key const * their_identity_key, _olm_curve25519_public_key const * their_identity_key,
std::uint8_t const * pre_key_message, std::size_t message_length std::uint8_t const * pre_key_message, std::size_t message_length
); ) const;
/** Whether the next message will be a pre-key message or a normal message. /** Whether the next message will be a pre-key message or a normal message.
* An outbound session will send pre-key messages until it receives a * An outbound session will send pre-key messages until it receives a
* message with a ratchet key. */ * message with a ratchet key. */
MessageType encrypt_message_type(); MessageType encrypt_message_type() const;
std::size_t encrypt_message_length( std::size_t encrypt_message_length(
std::size_t plaintext_length std::size_t plaintext_length
); ) const;
/** The number of bytes of random data the encrypt method will need to /** The number of bytes of random data the encrypt method will need to
* encrypt a message. This will be 32 bytes if the session needs to * encrypt a message. This will be 32 bytes if the session needs to
* generate a new ephemeral key, or will be 0 bytes otherwise. */ * generate a new ephemeral key, or will be 0 bytes otherwise. */
std::size_t encrypt_random_length(); std::size_t encrypt_random_length() const;
/** Encrypt some plain-text. Returns the length of the encrypted message /** Encrypt some plain-text. Returns the length of the encrypted message
* or std::size_t(-1) on failure. On failure last_error will be set with * or std::size_t(-1) on failure. On failure last_error will be set with
......
...@@ -32,7 +32,7 @@ struct Utility { ...@@ -32,7 +32,7 @@ struct Utility {
OlmErrorCode last_error; OlmErrorCode last_error;
/** The length of a SHA-256 hash in bytes. */ /** The length of a SHA-256 hash in bytes. */
std::size_t sha256_length(); std::size_t sha256_length() const;
/** Compute a SHA-256 hash. Returns the length of the SHA-256 hash in bytes /** Compute a SHA-256 hash. Returns the length of the SHA-256 hash in bytes
* on success. Returns std::size_t(-1) on failure. On failure last_error * on success. Returns std::size_t(-1) on failure. On failure last_error
......
{ {
global: olm*; _olm*; megolm*; _ZN3olm*; global: olm*; _olm*; megolm*; _ZN3olm*; _ZNK3olm*;
local: *; local: *;
}; };
...@@ -84,7 +84,7 @@ std::size_t olm::Account::remove_key( ...@@ -84,7 +84,7 @@ std::size_t olm::Account::remove_key(
return std::size_t(-1); return std::size_t(-1);
} }
std::size_t olm::Account::new_account_random_length() { std::size_t olm::Account::new_account_random_length() const {
return ED25519_RANDOM_LENGTH + CURVE25519_RANDOM_LENGTH; return ED25519_RANDOM_LENGTH + CURVE25519_RANDOM_LENGTH;
} }
...@@ -120,7 +120,7 @@ static std::uint8_t * write_string( ...@@ -120,7 +120,7 @@ static std::uint8_t * write_string(
} }
std::size_t olm::Account::get_identity_json_length() { std::size_t olm::Account::get_identity_json_length() const {
std::size_t length = 0; std::size_t length = 0;
length += 1; /* { */ length += 1; /* { */
length += sizeof(KEY_JSON_CURVE25519) - 1; length += sizeof(KEY_JSON_CURVE25519) - 1;
...@@ -172,7 +172,7 @@ std::size_t olm::Account::get_identity_json( ...@@ -172,7 +172,7 @@ std::size_t olm::Account::get_identity_json(
std::size_t olm::Account::signature_length( std::size_t olm::Account::signature_length(
) { ) const {
return ED25519_SIGNATURE_LENGTH; return ED25519_SIGNATURE_LENGTH;
} }
...@@ -193,7 +193,7 @@ std::size_t olm::Account::sign( ...@@ -193,7 +193,7 @@ std::size_t olm::Account::sign(
std::size_t olm::Account::get_one_time_keys_json_length( std::size_t olm::Account::get_one_time_keys_json_length(
) { ) const {
std::size_t length = 0; std::size_t length = 0;
bool is_empty = true; bool is_empty = true;
for (auto const & key : one_time_keys) { for (auto const & key : one_time_keys) {
...@@ -267,13 +267,13 @@ std::size_t olm::Account::mark_keys_as_published( ...@@ -267,13 +267,13 @@ std::size_t olm::Account::mark_keys_as_published(
std::size_t olm::Account::max_number_of_one_time_keys( std::size_t olm::Account::max_number_of_one_time_keys(
) { ) const {
return olm::MAX_ONE_TIME_KEYS; return olm::MAX_ONE_TIME_KEYS;
} }
std::size_t olm::Account::generate_one_time_keys_random_length( std::size_t olm::Account::generate_one_time_keys_random_length(
std::size_t number_of_keys std::size_t number_of_keys
) { ) const {
return CURVE25519_RANDOM_LENGTH * number_of_keys; return CURVE25519_RANDOM_LENGTH * number_of_keys;
} }
...@@ -295,7 +295,7 @@ std::size_t olm::Account::generate_one_time_keys( ...@@ -295,7 +295,7 @@ std::size_t olm::Account::generate_one_time_keys(
return number_of_keys; return number_of_keys;
} }
std::size_t olm::Account::generate_fallback_key_random_length() { std::size_t olm::Account::generate_fallback_key_random_length() const {
return CURVE25519_RANDOM_LENGTH; return CURVE25519_RANDOM_LENGTH;
} }
...@@ -315,9 +315,9 @@ std::size_t olm::Account::generate_fallback_key( ...@@ -315,9 +315,9 @@ std::size_t olm::Account::generate_fallback_key(
std::size_t olm::Account::get_fallback_key_json_length( std::size_t olm::Account::get_fallback_key_json_length(
) { ) const {
std::size_t length = 4 + sizeof(KEY_JSON_CURVE25519) - 1; /* {"curve25519":{}} */