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 {
OlmErrorCode last_error;
/** 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
* random bytes is too small then last_error will be NOT_ENOUGH_RANDOM */
......@@ -58,7 +58,7 @@ struct 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
* format:
......@@ -77,7 +77,7 @@ struct Account {
/**
* 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.
......@@ -88,7 +88,7 @@ struct 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:
*
......@@ -111,13 +111,13 @@ struct Account {
std::size_t mark_keys_as_published();
/** 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
* time keys. */
std::size_t generate_one_time_keys_random_length(
std::size_t number_of_keys
);
) const;
/** 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
......@@ -129,7 +129,7 @@ struct Account {
);
/** 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
* number of random bytes is too small then last_error will be
......@@ -139,7 +139,7 @@ struct 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:
*
......
......@@ -119,12 +119,12 @@ size_t olm_clear_utility(
/** Returns the number of bytes needed to store an account */
size_t olm_pickle_account_length(
OlmAccount * account
const OlmAccount * account
);
/** Returns the number of bytes needed to store a session */
size_t olm_pickle_session_length(
OlmSession * session
const OlmSession * session
);
/** Stores an account as a base64 string. Encrypts the account using the
......@@ -175,7 +175,7 @@ size_t olm_unpickle_session(
/** The number of random bytes needed to create an account.*/
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
......@@ -188,7 +188,7 @@ size_t olm_create_account(
/** The size of the output buffer needed to hold the identity keys */
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
......@@ -203,7 +203,7 @@ size_t olm_account_identity_keys(
/** The length of an ed25519 signature encoded as base64. */
size_t olm_account_signature_length(
OlmAccount * account
const OlmAccount * account
);
/** Signs a message with the ed25519 key for this account. Returns olm_error()
......@@ -217,7 +217,7 @@ size_t olm_account_sign(
/** The size of the output buffer needed to hold the one time keys */
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
......@@ -250,13 +250,13 @@ size_t olm_account_mark_keys_as_published(
/** The largest number of one time keys this account can store. */
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
* time keys. */
size_t olm_account_generate_one_time_keys_random_length(
OlmAccount * account,
const OlmAccount * account,
size_t number_of_keys
);
......@@ -272,7 +272,7 @@ size_t olm_account_generate_one_time_keys(
/** The number of random bytes needed to generate a fallback key. */
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
......@@ -286,7 +286,7 @@ size_t olm_account_generate_fallback_key(
/** The number of bytes needed to hold the fallback key as returned by
* olm_account_fallback_key. */
size_t olm_account_fallback_key_length(
OlmAccount * account
const OlmAccount * account
);
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 */
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
......@@ -339,7 +339,7 @@ size_t olm_create_inbound_session_from(
/** The length of the buffer needed to return the id for this session. */
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
......@@ -351,7 +351,7 @@ size_t olm_session_id(
);
int olm_session_has_received_message(
OlmSession *session
const OlmSession *session
);
/**
......@@ -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_error on failure. */
size_t olm_encrypt_message_type(
OlmSession * session
const OlmSession * session
);
/** The number of random bytes needed to encrypt the next message. */
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
* bytes. */
size_t olm_encrypt_message_length(
OlmSession * session,
const OlmSession * session,
size_t plaintext_length
);
......@@ -464,7 +464,7 @@ size_t olm_decrypt(
/** The length of the buffer needed to hold the SHA-256 hash. */
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
......
......@@ -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
* given length. */
size_t olm_pk_ciphertext_length(
OlmPkEncryption *encryption,
const OlmPkEncryption *encryption,
size_t plaintext_length
);
/** Get the length of the message authentication code. */
size_t olm_pk_mac_length(
OlmPkEncryption *encryption
const OlmPkEncryption *encryption
);
/** Get the length of a public or ephemeral key */
......@@ -76,7 +76,7 @@ size_t olm_pk_key_length(void);
/** The number of random bytes needed to encrypt a message. */
size_t olm_pk_encrypt_random_length(
OlmPkEncryption *encryption
const OlmPkEncryption *encryption
);
/** Encrypt a plaintext for the recipient set using
......@@ -160,7 +160,7 @@ size_t olm_pk_generate_key(
/** Returns the number of bytes needed to store a decryption object. */
size_t olm_pickle_pk_decryption_length(
OlmPkDecryption * decryption
const OlmPkDecryption * decryption
);
/** Stores decryption object as a base64 string. Encrypts the object using the
......@@ -191,7 +191,7 @@ size_t olm_unpickle_pk_decryption(
/** Get the length of the plaintext that will correspond to a ciphertext of the
* given length. */
size_t olm_pk_max_plaintext_length(
OlmPkDecryption * decryption,
const OlmPkDecryption * decryption,
size_t ciphertext_length
);
......
......@@ -124,12 +124,12 @@ struct Ratchet {
* a given message length. */
std::size_t encrypt_output_length(
std::size_t plaintext_length
);
) const;
/** 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
* 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
* or std::size_t(-1) on failure. On failure last_error will be set with
......
......@@ -61,7 +61,7 @@ size_t olm_clear_sas(
/** The number of random bytes needed to create an SAS object. */
size_t olm_create_sas_random_length(
OlmSAS * sas
const OlmSAS * sas
);
/** Creates a new SAS object.
......@@ -81,7 +81,7 @@ size_t olm_create_sas(
);
/** 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.
*
......@@ -119,7 +119,7 @@ size_t olm_sas_set_their_key(
*
*/
int olm_sas_is_their_key_set(
OlmSAS *sas
const OlmSAS *sas
);
/** Generate bytes to use for the short authentication string.
......@@ -144,7 +144,7 @@ size_t olm_sas_generate_bytes(
/** The size of the message authentication code generated by
* olm_sas_calculate_mac()`. */
size_t olm_sas_mac_length(
OlmSAS *sas
const OlmSAS *sas
);
/** Generate a message authentication code (MAC) based on the shared secret.
......
......@@ -41,7 +41,7 @@ struct Session {
/** 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. */
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
* failure last_error will be set with an error code. The last_error will be
......@@ -64,7 +64,7 @@ struct Session {
);
/** 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
* used to create the session. Returns the length of the session id on
......@@ -84,21 +84,21 @@ struct Session {
bool matches_inbound_session(
_olm_curve25519_public_key const * their_identity_key,
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.
* An outbound session will send pre-key messages until it receives a
* message with a ratchet key. */
MessageType encrypt_message_type();
MessageType encrypt_message_type() const;
std::size_t encrypt_message_length(
std::size_t plaintext_length
);
) const;
/** 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
* 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
* or std::size_t(-1) on failure. On failure last_error will be set with
......
......@@ -32,7 +32,7 @@ struct Utility {
OlmErrorCode last_error;
/** 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
* 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: *;
};
......@@ -84,7 +84,7 @@ std::size_t olm::Account::remove_key(
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;
}
......@@ -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;
length += 1; /* { */
length += sizeof(KEY_JSON_CURVE25519) - 1;
......@@ -172,7 +172,7 @@ std::size_t olm::Account::get_identity_json(
std::size_t olm::Account::signature_length(
) {
) const {
return ED25519_SIGNATURE_LENGTH;
}
......@@ -193,7 +193,7 @@ std::size_t olm::Account::sign(
std::size_t olm::Account::get_one_time_keys_json_length(
) {
) const {
std::size_t length = 0;
bool is_empty = true;
for (auto const & key : one_time_keys) {
......@@ -267,13 +267,13 @@ std::size_t olm::Account::mark_keys_as_published(
std::size_t olm::Account::max_number_of_one_time_keys(
) {
) const {
return olm::MAX_ONE_TIME_KEYS;
}
std::size_t olm::Account::generate_one_time_keys_random_length(
std::size_t number_of_keys
) {
) const {
return CURVE25519_RANDOM_LENGTH * number_of_keys;
}
......@@ -295,7 +295,7 @@ std::size_t olm::Account::generate_one_time_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;
}
......@@ -315,9 +315,9 @@ std::size_t olm::Account::generate_fallback_key(
std::size_t olm::Account::get_fallback_key_json_length(
) {
) const {
std::size_t length = 4 + sizeof(KEY_JSON_CURVE25519) - 1; /* {"curve25519":{}} */
OneTimeKey & key = current_fallback_key;
const OneTimeKey & key = current_fallback_key;
if (key.published) {
length += 1; /* " */
length += olm::encode_base64_length(_olm_pickle_uint32_length(key.id));
......
......@@ -231,14 +231,14 @@ size_t olm_clear_utility(
size_t olm_pickle_account_length(
OlmAccount * account
const OlmAccount * account
) {
return _olm_enc_output_length(pickle_length(*from_c(account)));
}
size_t olm_pickle_session_length(
OlmSession * session
const OlmSession * session
) {
return _olm_enc_output_length(pickle_length(*from_c(session)));
}
......@@ -334,7 +334,7 @@ size_t olm_unpickle_session(
size_t olm_create_account_random_length(
OlmAccount * account
const OlmAccount * account
) {
return from_c(account)->new_account_random_length();
}
......@@ -351,7 +351,7 @@ size_t olm_create_account(
size_t olm_account_identity_keys_length(
OlmAccount * account
const OlmAccount * account
) {
return from_c(account)->get_identity_json_length();
}
......@@ -368,7 +368,7 @@ size_t olm_account_identity_keys(
size_t olm_account_signature_length(
OlmAccount * account
const OlmAccount * account
) {
return b64_output_length(from_c(account)->signature_length());
}
......@@ -394,7 +394,7 @@ size_t olm_account_sign(
size_t olm_account_one_time_keys_length(
OlmAccount * account
const OlmAccount * account
) {
return from_c(account)->get_one_time_keys_json_length();
}
......@@ -418,14 +418,14 @@ size_t olm_account_mark_keys_as_published(
size_t olm_account_max_number_of_one_time_keys(
OlmAccount * account
const OlmAccount * account
) {
return from_c(account)->max_number_of_one_time_keys();
}
size_t olm_account_generate_one_time_keys_random_length(
OlmAccount * account,
const OlmAccount * account,
size_t number_of_keys
) {
return from_c(account)->generate_one_time_keys_random_length(number_of_keys);
......@@ -447,7 +447,7 @@ size_t olm_account_generate_one_time_keys(
size_t olm_account_generate_fallback_key_random_length(
OlmAccount * account
const OlmAccount * account
) {
return from_c(account)->generate_fallback_key_random_length();
}
......@@ -466,7 +466,7 @@ size_t olm_account_generate_fallback_key(
size_t olm_account_fallback_key_length(
OlmAccount * account
const OlmAccount * account
) {
return from_c(account)->get_fallback_key_json_length();
}
......@@ -483,7 +483,7 @@ size_t olm_account_fallback_key(
size_t olm_create_outbound_session_random_length(
OlmSession * session
const OlmSession * session
) {
return from_c(session)->new_outbound_session_random_length();
}
......@@ -569,7 +569,7 @@ size_t olm_create_inbound_session_from(
size_t olm_session_id_length(
OlmSession * session
const OlmSession * session
) {
return b64_output_length(from_c(session)->session_id_length());
}
......@@ -595,7 +595,7 @@ size_t olm_session_id(
int olm_session_has_received_message(
OlmSession * session
const OlmSession * session
) {
return from_c(session)->received_message;
}
......@@ -666,21 +666,21 @@ size_t olm_remove_one_time_keys(
size_t olm_encrypt_message_type(
OlmSession * session
const OlmSession * session
) {
return size_t(from_c(session)->encrypt_message_type());
}
size_t olm_encrypt_random_length(
OlmSession * session
const OlmSession * session
) {
return from_c(session)->encrypt_random_length();
}
size_t olm_encrypt_message_length(
OlmSession * session,
const OlmSession * session,
size_t plaintext_length
) {
return b64_output_length(
......@@ -753,7 +753,7 @@ size_t olm_decrypt(
size_t olm_sha256_length(
OlmUtility * utility
const OlmUtility * utility
) {
return b64_output_length(from_c(utility)->sha256_length());
}
......
......@@ -90,7 +90,7 @@ size_t olm_pk_encryption_set_recipient_key (
}
size_t olm_pk_ciphertext_length(
OlmPkEncryption *encryption,
const OlmPkEncryption *encryption,
size_t plaintext_length
) {
return olm::encode_base64_length(
......@@ -99,13 +99,13 @@ size_t olm_pk_ciphertext_length(
}
size_t olm_pk_mac_length(
OlmPkEncryption *encryption
const OlmPkEncryption *encryption
) {
return olm::encode_base64_length(_olm_cipher_aes_sha_256_ops.mac_length(olm_pk_cipher));
}
size_t olm_pk_encrypt_random_length(
OlmPkEncryption *encryption
const OlmPkEncryption *encryption
) {
return CURVE25519_KEY_LENGTH;
}
......@@ -291,7 +291,7 @@ namespace {
}
size_t olm_pickle_pk_decryption_length(
OlmPkDecryption * decryption
const OlmPkDecryption * decryption
) {
return _olm_enc_output_length(pickle_length(*decryption));
}
......@@ -355,7 +355,7 @@ size_t olm_unpickle_pk_decryption(
}
size_t olm_pk_max_plaintext_length(
OlmPkDecryption * decryption,
const OlmPkDecryption * decryption,
size_t ciphertext_length
) {
return _olm_cipher_aes_sha_256_ops.decrypt_max_plaintext_length(
......
......@@ -399,7 +399,7 @@ std::uint8_t const * olm::unpickle(
std::size_t olm::Ratchet::encrypt_output_length(
std::size_t plaintext_length
) {
) const {
std::size_t counter = 0;
if (!sender_chain.empty()) {
counter = sender_chain[0].chain_key.index;
......@@ -414,7 +414,7 @@ std::size_t olm::Ratchet::encrypt_output_length(
}
std::size_t olm::Ratchet::encrypt_random_length() {
std::size_t olm::Ratchet::encrypt_random_length() const {
return sender_chain.empty() ? CURVE25519_RANDOM_LENGTH : 0;
}
......
......@@ -56,7 +56,7 @@ size_t olm_clear_sas(
return sizeof(OlmSAS);
}
size_t olm_create_sas_random_length(OlmSAS * sas) {
size_t olm_create_sas_random_length(const OlmSAS * sas) {
return CURVE25519_KEY_LENGTH;
}
......@@ -73,7 +73,7 @@ size_t olm_create_sas(
return 0;
}
size_t olm_sas_pubkey_length(OlmSAS * sas) {
size_t olm_sas_pubkey_length(const OlmSAS * sas) {
return _olm_encode_base64_length(CURVE25519_KEY_LENGTH);