aboutsummaryrefslogtreecommitdiff
path: root/src/olm.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-07-07 16:42:03 +0100
committerMark Haines <mark.haines@matrix.org>2015-07-07 16:42:03 +0100
commit3a382aec59937b086c37f039f1b011f253e80e97 (patch)
tree9c544b2fa307b4920e0f945e05cff3251db524e6 /src/olm.cpp
parent2a873fd4e1d53c45898b27e1c953b551b2cf6023 (diff)
Encode the account keys as a signed JSON object
Diffstat (limited to 'src/olm.cpp')
-rw-r--r--src/olm.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/olm.cpp b/src/olm.cpp
index 3aab4e2..a9735a5 100644
--- a/src/olm.cpp
+++ b/src/olm.cpp
@@ -325,8 +325,8 @@ namespace {
static const std::size_t OUTPUT_KEY_LENGTH = 2 + 10 + 2 +
olm::encode_base64_length(32) + 3;
-void output_key(
- olm::LocalKey const & key,
+void output_one_time_key(
+ olm::OneTimeKey const & key,
std::uint8_t sep,
std::uint8_t * output
) {
@@ -353,27 +353,35 @@ void output_key(
size_t olm_account_identity_keys_length(
- OlmAccount * account
-) {
- return OUTPUT_KEY_LENGTH + 1;
+ OlmAccount * account,
+ size_t user_id_length,
+ size_t device_id_length,
+ uint64_t valid_after_ts,
+ uint64_t valid_until_ts
+) {
+ return from_c(account)->get_identity_json_length(
+ user_id_length,
+ device_id_length,
+ valid_after_ts,
+ valid_until_ts
+ );
}
-
size_t olm_account_identity_keys(
OlmAccount * account,
+ void const * user_id, size_t user_id_length,
+ void const * device_id, size_t device_id_length,
+ uint64_t valid_after_ts,
+ uint64_t valid_until_ts,
void * identity_keys, size_t identity_key_length
) {
- std::size_t length = olm_account_identity_keys_length(account);
- if (identity_key_length < length) {
- from_c(account)->last_error =
- olm::ErrorCode::OUTPUT_BUFFER_TOO_SMALL;
- return size_t(-1);
- }
- std::uint8_t * output = from_c(identity_keys);
- output_key(from_c(account)->identity_key, '[', output);
- output += OUTPUT_KEY_LENGTH;
- output[0] = ']';
- return length;
+ return from_c(account)->get_identity_json(
+ from_c(user_id), user_id_length,
+ from_c(device_id), device_id_length,
+ valid_after_ts,
+ valid_until_ts,
+ from_c(identity_keys), identity_key_length
+ );
}
@@ -381,7 +389,7 @@ size_t olm_account_one_time_keys_length(
OlmAccount * account
) {
size_t count = from_c(account)->one_time_keys.size();
- return OUTPUT_KEY_LENGTH * (count + 1) + 1;
+ return OUTPUT_KEY_LENGTH * count + 1;
}
@@ -397,9 +405,8 @@ size_t olm_account_one_time_keys(
}
std::uint8_t * output = from_c(identity_keys);
std::uint8_t sep = '[';
- output += OUTPUT_KEY_LENGTH;
for (auto const & key : from_c(account)->one_time_keys) {
- output_key(key, sep, output);
+ output_one_time_key(key, sep, output);
output += OUTPUT_KEY_LENGTH;
sep = ',';
}