Make the internal functions static, remove some unused internal functions
This commit is contained in:
parent
c35d1d420f
commit
159faa1e2b
5 changed files with 25 additions and 59 deletions
|
@ -69,26 +69,11 @@ std::size_t olm::Account::new_account(
|
|||
|
||||
namespace {
|
||||
|
||||
|
||||
namespace {
|
||||
uint8_t KEY_JSON_ED25519[] = "\"ed25519\":";
|
||||
uint8_t KEY_JSON_CURVE25519[] = "\"curve25519\":";
|
||||
}
|
||||
|
||||
|
||||
std::size_t count_digits(
|
||||
std::uint64_t value
|
||||
) {
|
||||
std::size_t digits = 0;
|
||||
do {
|
||||
digits++;
|
||||
value /= 10;
|
||||
} while (value);
|
||||
return digits;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::uint8_t * write_string(
|
||||
static std::uint8_t * write_string(
|
||||
std::uint8_t * pos,
|
||||
T const & value
|
||||
) {
|
||||
|
@ -96,27 +81,6 @@ std::uint8_t * write_string(
|
|||
return pos + (sizeof(T) - 1);
|
||||
}
|
||||
|
||||
std::uint8_t * write_string(
|
||||
std::uint8_t * pos,
|
||||
std::uint8_t const * value, std::size_t value_length
|
||||
) {
|
||||
std::memcpy(pos, value, value_length);
|
||||
return pos + value_length;
|
||||
}
|
||||
|
||||
std::uint8_t * write_digits(
|
||||
std::uint8_t * pos,
|
||||
std::uint64_t value
|
||||
) {
|
||||
size_t digits = count_digits(value);
|
||||
pos += digits;
|
||||
do {
|
||||
*(--pos) = '0' + (value % 10);
|
||||
value /= 10;
|
||||
} while (value);
|
||||
return pos + digits;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -196,19 +160,20 @@ std::size_t olm::Account::sign(
|
|||
std::size_t olm::Account::get_one_time_keys_json_length(
|
||||
) {
|
||||
std::size_t length = 0;
|
||||
bool is_empty = true;
|
||||
for (auto const & key : one_time_keys) {
|
||||
if (key.published) {
|
||||
continue;
|
||||
}
|
||||
is_empty = false;
|
||||
length += 2; /* {" */
|
||||
length += olm::encode_base64_length(olm::pickle_length(key.id));
|
||||
length += 3; /* ":" */
|
||||
length += olm::encode_base64_length(sizeof(key.key.public_key));
|
||||
length += 1; /* " */
|
||||
}
|
||||
if (length == 0) {
|
||||
/* The list was empty. Add a byte for the opening '{' */
|
||||
length = 1;
|
||||
if (is_empty) {
|
||||
length += 1; /* { */
|
||||
}
|
||||
length += 3; /* }{} */
|
||||
length += sizeof(KEY_JSON_CURVE25519) - 1;
|
||||
|
@ -244,6 +209,7 @@ std::size_t olm::Account::get_one_time_keys_json(
|
|||
sep = ',';
|
||||
}
|
||||
if (sep != ',') {
|
||||
/* The list was empty */
|
||||
*(pos++) = sep;
|
||||
}
|
||||
*(pos++) = '}';
|
||||
|
|
|
@ -99,7 +99,7 @@ inline static void hmac_sha256_key(
|
|||
}
|
||||
|
||||
|
||||
inline void hmac_sha256_init(
|
||||
inline static void hmac_sha256_init(
|
||||
::SHA256_CTX * context,
|
||||
std::uint8_t const * hmac_key
|
||||
) {
|
||||
|
@ -114,7 +114,7 @@ inline void hmac_sha256_init(
|
|||
}
|
||||
|
||||
|
||||
inline void hmac_sha256_final(
|
||||
inline static void hmac_sha256_final(
|
||||
::SHA256_CTX * context,
|
||||
std::uint8_t const * hmac_key,
|
||||
std::uint8_t * output
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
namespace {
|
||||
|
||||
template<typename T>
|
||||
std::size_t varint_length(
|
||||
static std::size_t varint_length(
|
||||
T value
|
||||
) {
|
||||
std::size_t result = 1;
|
||||
|
@ -30,7 +30,7 @@ std::size_t varint_length(
|
|||
|
||||
|
||||
template<typename T>
|
||||
std::uint8_t * varint_encode(
|
||||
static std::uint8_t * varint_encode(
|
||||
std::uint8_t * output,
|
||||
T value
|
||||
) {
|
||||
|
@ -44,7 +44,7 @@ std::uint8_t * varint_encode(
|
|||
|
||||
|
||||
template<typename T>
|
||||
T varint_decode(
|
||||
static T varint_decode(
|
||||
std::uint8_t const * varint_start,
|
||||
std::uint8_t const * varint_end
|
||||
) {
|
||||
|
@ -60,7 +60,7 @@ T varint_decode(
|
|||
}
|
||||
|
||||
|
||||
std::uint8_t const * varint_skip(
|
||||
static std::uint8_t const * varint_skip(
|
||||
std::uint8_t const * input,
|
||||
std::uint8_t const * input_end
|
||||
) {
|
||||
|
@ -74,7 +74,7 @@ std::uint8_t const * varint_skip(
|
|||
}
|
||||
|
||||
|
||||
std::size_t varstring_length(
|
||||
static std::size_t varstring_length(
|
||||
std::size_t string_length
|
||||
) {
|
||||
return varint_length(string_length) + string_length;
|
||||
|
@ -85,7 +85,7 @@ static std::uint8_t const RATCHET_KEY_TAG = 012;
|
|||
static std::uint8_t const COUNTER_TAG = 020;
|
||||
static std::uint8_t const CIPHERTEXT_TAG = 042;
|
||||
|
||||
std::uint8_t * encode(
|
||||
static std::uint8_t * encode(
|
||||
std::uint8_t * pos,
|
||||
std::uint8_t tag,
|
||||
std::uint32_t value
|
||||
|
@ -94,7 +94,7 @@ std::uint8_t * encode(
|
|||
return varint_encode(pos, value);
|
||||
}
|
||||
|
||||
std::uint8_t * encode(
|
||||
static std::uint8_t * encode(
|
||||
std::uint8_t * pos,
|
||||
std::uint8_t tag,
|
||||
std::uint8_t * & value, std::size_t value_length
|
||||
|
@ -105,7 +105,7 @@ std::uint8_t * encode(
|
|||
return pos + value_length;
|
||||
}
|
||||
|
||||
std::uint8_t const * decode(
|
||||
static std::uint8_t const * decode(
|
||||
std::uint8_t const * pos, std::uint8_t const * end,
|
||||
std::uint8_t tag,
|
||||
std::uint32_t & value, bool & has_value
|
||||
|
@ -121,7 +121,7 @@ std::uint8_t const * decode(
|
|||
}
|
||||
|
||||
|
||||
std::uint8_t const * decode(
|
||||
static std::uint8_t const * decode(
|
||||
std::uint8_t const * pos, std::uint8_t const * end,
|
||||
std::uint8_t tag,
|
||||
std::uint8_t const * & value, std::size_t & value_length
|
||||
|
@ -139,7 +139,7 @@ std::uint8_t const * decode(
|
|||
return pos;
|
||||
}
|
||||
|
||||
std::uint8_t const * skip_unknown(
|
||||
static std::uint8_t const * skip_unknown(
|
||||
std::uint8_t const * pos, std::uint8_t const * end
|
||||
) {
|
||||
if (pos != end) {
|
||||
|
|
|
@ -29,7 +29,7 @@ std::uint8_t MESSAGE_KEY_SEED[1] = {0x01};
|
|||
std::uint8_t CHAIN_KEY_SEED[1] = {0x02};
|
||||
std::size_t MAX_MESSAGE_GAP = 2000;
|
||||
|
||||
void create_chain_key(
|
||||
static void create_chain_key(
|
||||
olm::SharedKey const & root_key,
|
||||
olm::Curve25519KeyPair const & our_key,
|
||||
olm::Curve25519PublicKey const & their_key,
|
||||
|
@ -54,7 +54,7 @@ void create_chain_key(
|
|||
}
|
||||
|
||||
|
||||
void advance_chain_key(
|
||||
static void advance_chain_key(
|
||||
olm::ChainKey const & chain_key,
|
||||
olm::ChainKey & new_chain_key
|
||||
) {
|
||||
|
@ -67,7 +67,7 @@ void advance_chain_key(
|
|||
}
|
||||
|
||||
|
||||
void create_message_keys(
|
||||
static void create_message_keys(
|
||||
olm::ChainKey const & chain_key,
|
||||
olm::KdfInfo const & info,
|
||||
olm::MessageKey & message_key
|
||||
|
@ -81,7 +81,7 @@ void create_message_keys(
|
|||
}
|
||||
|
||||
|
||||
std::size_t verify_mac_and_decrypt(
|
||||
static std::size_t verify_mac_and_decrypt(
|
||||
olm::Cipher const & cipher,
|
||||
olm::MessageKey const & message_key,
|
||||
olm::MessageReader const & reader,
|
||||
|
@ -96,7 +96,7 @@ std::size_t verify_mac_and_decrypt(
|
|||
}
|
||||
|
||||
|
||||
std::size_t verify_mac_and_decrypt_for_existing_chain(
|
||||
static std::size_t verify_mac_and_decrypt_for_existing_chain(
|
||||
olm::Ratchet const & session,
|
||||
olm::ChainKey const & chain,
|
||||
olm::MessageReader const & reader,
|
||||
|
@ -130,7 +130,7 @@ std::size_t verify_mac_and_decrypt_for_existing_chain(
|
|||
}
|
||||
|
||||
|
||||
std::size_t verify_mac_and_decrypt_for_new_chain(
|
||||
static std::size_t verify_mac_and_decrypt_for_new_chain(
|
||||
olm::Ratchet const & session,
|
||||
olm::MessageReader const & reader,
|
||||
std::uint8_t * plaintext, std::size_t max_plaintext_length
|
||||
|
|
|
@ -101,7 +101,7 @@ std::size_t olm::Session::new_outbound_session(
|
|||
|
||||
namespace {
|
||||
|
||||
bool check_message_fields(
|
||||
static bool check_message_fields(
|
||||
olm::PreKeyMessageReader & reader, bool have_their_identity_key
|
||||
) {
|
||||
bool ok = true;
|
||||
|
|
Loading…
Reference in a new issue