aboutsummaryrefslogtreecommitdiff
path: root/src/olm.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-08-19 17:18:09 +0100
committerMark Haines <mark.haines@matrix.org>2015-08-19 17:32:06 +0100
commitb3180551851d6f736a98eb059d5b46b0872666e2 (patch)
treeeab45e085474fe190d9a87d16ed284a407d96925 /src/olm.cpp
parenta378a40b3a139b789b00d778c1091a0818c4a8ad (diff)
Replace hard coded references to the 32-byte key length with a constant, add utilities for copying data to and from fixed sized arrays
Diffstat (limited to 'src/olm.cpp')
-rw-r--r--src/olm.cpp47
1 files changed, 21 insertions, 26 deletions
diff --git a/src/olm.cpp b/src/olm.cpp
index 28b194f..63f3d83 100644
--- a/src/olm.cpp
+++ b/src/olm.cpp
@@ -520,8 +520,13 @@ size_t olm_create_outbound_session(
void const * their_one_time_key, size_t their_one_time_key_length,
void * random, size_t random_length
) {
- if (olm::decode_base64_length(their_identity_key_length) != 32
- || olm::decode_base64_length(their_one_time_key_length) != 32
+ std::uint8_t const * id_key = from_c(their_identity_key);
+ std::uint8_t const * ot_key = from_c(their_one_time_key);
+ std::size_t id_key_length = their_identity_key_length;
+ std::size_t ot_key_length = their_one_time_key_length;
+
+ if (olm::decode_base64_length(id_key_length) != olm::KEY_LENGTH
+ || olm::decode_base64_length(ot_key_length) != olm::KEY_LENGTH
) {
from_c(session)->last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
@@ -529,14 +534,8 @@ size_t olm_create_outbound_session(
olm::Curve25519PublicKey identity_key;
olm::Curve25519PublicKey one_time_key;
- olm::decode_base64(
- from_c(their_identity_key), their_identity_key_length,
- identity_key.public_key
- );
- olm::decode_base64(
- from_c(their_one_time_key), their_one_time_key_length,
- one_time_key.public_key
- );
+ olm::decode_base64(id_key, id_key_length, identity_key.public_key);
+ olm::decode_base64(ot_key, ot_key_length, one_time_key.public_key);
size_t result = from_c(session)->new_outbound_session(
*from_c(account), identity_key, one_time_key,
@@ -570,15 +569,15 @@ size_t olm_create_inbound_session_from(
void const * their_identity_key, size_t their_identity_key_length,
void * one_time_key_message, size_t message_length
) {
- if (olm::decode_base64_length(their_identity_key_length) != 32) {
+ std::uint8_t const * id_key = from_c(their_identity_key);
+ std::size_t id_key_length = their_identity_key_length;
+
+ if (olm::decode_base64_length(id_key_length) != olm::KEY_LENGTH) {
from_c(session)->last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
}
olm::Curve25519PublicKey identity_key;
- olm::decode_base64(
- from_c(their_identity_key), their_identity_key_length,
- identity_key.public_key
- );
+ olm::decode_base64(id_key, id_key_length, identity_key.public_key);
std::size_t raw_length = b64_input(
from_c(one_time_key_message), message_length, from_c(session)->last_error
@@ -641,15 +640,15 @@ size_t olm_matches_inbound_session_from(
void const * their_identity_key, size_t their_identity_key_length,
void * one_time_key_message, size_t message_length
) {
- if (olm::decode_base64_length(their_identity_key_length) != 32) {
+ std::uint8_t const * id_key = from_c(their_identity_key);
+ std::size_t id_key_length = their_identity_key_length;
+
+ if (olm::decode_base64_length(id_key_length) != olm::KEY_LENGTH) {
from_c(session)->last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
}
olm::Curve25519PublicKey identity_key;
- olm::decode_base64(
- from_c(their_identity_key), their_identity_key_length,
- identity_key.public_key
- );
+ olm::decode_base64(id_key, id_key_length, identity_key.public_key);
std::size_t raw_length = b64_input(
from_c(one_time_key_message), message_length, from_c(session)->last_error
@@ -800,15 +799,12 @@ size_t olm_ed25519_verify(
void const * message, size_t message_length,
void * signature, size_t signature_length
) {
- if (olm::decode_base64_length(key_length) != 32) {
+ if (olm::decode_base64_length(key_length) != olm::KEY_LENGTH) {
from_c(utility)->last_error = olm::ErrorCode::INVALID_BASE64;
return std::size_t(-1);
}
olm::Ed25519PublicKey verify_key;
- olm::decode_base64(
- from_c(key), key_length,
- verify_key.public_key
- );
+ olm::decode_base64(from_c(key), key_length, verify_key.public_key);
std::size_t raw_signature_length = b64_input(
from_c(signature), signature_length, from_c(utility)->last_error
);
@@ -822,5 +818,4 @@ size_t olm_ed25519_verify(
);
}
-
}