From 532dc0d4e79192a0c7fd1758322f6cae06959859 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 8 Jul 2015 15:30:34 +0100 Subject: Change the JSON format for one time keys to include what algorithm they are for --- include/olm/account.hh | 46 ++++++++++++++++++++++++++++++---------------- include/olm/base64.hh | 10 ++++++---- 2 files changed, 36 insertions(+), 20 deletions(-) (limited to 'include/olm') diff --git a/include/olm/account.hh b/include/olm/account.hh index 98b6b56..552f069 100644 --- a/include/olm/account.hh +++ b/include/olm/account.hh @@ -63,34 +63,36 @@ struct Account { /** Output the identity keys for this account as JSON in the following * format. * - * 14 "{\"algorithms\":" - * 30 "[\"m.olm.curve25519-aes-sha256\"" - * 15 "],\"device_id\":\"" + * 14 {"algorithms": + * 30 ["m.olm.curve25519-aes-sha256" + * 15 ],"device_id":" * ? - * 22 "\",\"keys\":{\"curve25519:" + * 22 ","keys":{"curve25519: * 4 - * 3 "\":\"" + * 3 ":" * 43 - * 11 "\",\"ed25519:" + * 11 ","ed25519: * 4 - * 3 "\":\"" + * 3 ":" * 43 - * 14 "\"},\"user_id\":\"" + * 14 "},"user_id":" * ? - * 19 "\",\"valid_after_ts\":" + * 19 ","valid_after_ts": * ? - * 18 ",\"valid_until_ts\":" + * 18 ,"valid_until_ts": * ? - * 16 ",\"signatures\":{\"" + * 16 ,"signatures":{" * ? - * 1 "/" + * 1 / * ? - * 12 "\":{\"ed25519:" + * 12 ":{"ed25519: * 4 - * 3 "\":\"" + * 3 ":" * 86 - * 4 "\"}}}" - */ + * 4 "}}} + * + * Returns the size of the JSON written or std::size_t(-1) on error. + * If the buffer is too small last_error will be OUTPUT_BUFFER_TOO_SMALL. */ std::size_t get_identity_json( std::uint8_t const * user_id, std::size_t user_id_length, std::uint8_t const * device_id, std::size_t device_id_length, @@ -99,6 +101,18 @@ struct Account { std::uint8_t * identity_json, std::size_t identity_json_length ); + /** Number of bytes needed to output the one time keys for this account */ + std::size_t get_one_time_keys_json_length(); + + /* + * Returns the size of the JSON written or std::size_t(-1) on error. + * If the buffer is too small last_error will be OUTPUT_BUFFER_TOO_SMALL. + */ + std::size_t get_one_time_keys_json( + std::uint8_t * one_time_json, std::size_t one_time_json_length + ); + + /** Lookup a one_time key with the given key-id */ OneTimeKey const * lookup_key( Curve25519PublicKey const & public_key ); diff --git a/include/olm/base64.hh b/include/olm/base64.hh index a68894d..018924a 100644 --- a/include/olm/base64.hh +++ b/include/olm/base64.hh @@ -21,12 +21,14 @@ namespace olm { -std::size_t encode_base64_length( +static std::size_t encode_base64_length( std::size_t input_length -); +) { + return 4 * ((input_length + 2) / 3) + (input_length + 2) % 3 - 2; +} -void encode_base64( +std::uint8_t * encode_base64( std::uint8_t const * input, std::size_t input_length, std::uint8_t * output ); @@ -37,7 +39,7 @@ std::size_t decode_base64_length( ); -void decode_base64( +std::uint8_t const * decode_base64( std::uint8_t const * input, std::size_t input_length, std::uint8_t * output ); -- cgit v1.2.3