Commit a7310c58 authored by Richard van der Hoff's avatar Richard van der Hoff
Browse files

Return the base64-encoded length of pickles

make olm_pickle_* return the lengths of the base64-encoded pickles, rather than
the raw pickle. (From the application's POV, the format of the pickle is
opaque: it doesn't even know that it is base64-encoded. So returning the length
of the raw pickle is particularly unhelpful.)
parent d1a53586
...@@ -60,7 +60,7 @@ size_t _olm_enc_output( ...@@ -60,7 +60,7 @@ size_t _olm_enc_output(
raw_output, length raw_output, length
); );
_olm_encode_base64(raw_output, length, output); _olm_encode_base64(raw_output, length, output);
return raw_length; return base64_length;
} }
......
...@@ -28,23 +28,26 @@ int main() { ...@@ -28,23 +28,26 @@ int main() {
size_t pickle_length = olm_pickle_outbound_group_session_length(session); size_t pickle_length = olm_pickle_outbound_group_session_length(session);
uint8_t pickle1[pickle_length]; uint8_t pickle1[pickle_length];
olm_pickle_outbound_group_session(session, size_t res = olm_pickle_outbound_group_session(
"secret_key", 10, session, "secret_key", 10, pickle1, pickle_length
pickle1, pickle_length); );
assert_equals(pickle_length, res);
uint8_t pickle2[pickle_length]; uint8_t pickle2[pickle_length];
memcpy(pickle2, pickle1, pickle_length); memcpy(pickle2, pickle1, pickle_length);
uint8_t buffer2[size]; uint8_t buffer2[size];
OlmOutboundGroupSession *session2 = olm_outbound_group_session(buffer2); OlmOutboundGroupSession *session2 = olm_outbound_group_session(buffer2);
size_t res = olm_unpickle_outbound_group_session(session2, res = olm_unpickle_outbound_group_session(
"secret_key", 10, session2, "secret_key", 10, pickle2, pickle_length
pickle2, pickle_length); );
assert_not_equals((size_t)-1, res); assert_not_equals((size_t)-1, res);
assert_equals(pickle_length, assert_equals(pickle_length,
olm_pickle_outbound_group_session_length(session2)); olm_pickle_outbound_group_session_length(session2));
olm_pickle_outbound_group_session(session2, res = olm_pickle_outbound_group_session(
"secret_key", 10, session2, "secret_key", 10, pickle2, pickle_length
pickle2, pickle_length); );
assert_equals(pickle_length, res);
assert_equals(pickle1, pickle2, pickle_length); assert_equals(pickle1, pickle2, pickle_length);
} }
...@@ -59,23 +62,25 @@ int main() { ...@@ -59,23 +62,25 @@ int main() {
size_t pickle_length = olm_pickle_inbound_group_session_length(session); size_t pickle_length = olm_pickle_inbound_group_session_length(session);
uint8_t pickle1[pickle_length]; uint8_t pickle1[pickle_length];
olm_pickle_inbound_group_session(session, size_t res = olm_pickle_inbound_group_session(
"secret_key", 10, session, "secret_key", 10, pickle1, pickle_length
pickle1, pickle_length); );
assert_equals(pickle_length, res);
uint8_t pickle2[pickle_length]; uint8_t pickle2[pickle_length];
memcpy(pickle2, pickle1, pickle_length); memcpy(pickle2, pickle1, pickle_length);
uint8_t buffer2[size]; uint8_t buffer2[size];
OlmInboundGroupSession *session2 = olm_inbound_group_session(buffer2); OlmInboundGroupSession *session2 = olm_inbound_group_session(buffer2);
size_t res = olm_unpickle_inbound_group_session(session2, res = olm_unpickle_inbound_group_session(
"secret_key", 10, session2, "secret_key", 10, pickle2, pickle_length
pickle2, pickle_length); );
assert_not_equals((size_t)-1, res); assert_not_equals((size_t)-1, res);
assert_equals(pickle_length, assert_equals(pickle_length,
olm_pickle_inbound_group_session_length(session2)); olm_pickle_inbound_group_session_length(session2));
olm_pickle_inbound_group_session(session2, res = olm_pickle_inbound_group_session(
"secret_key", 10, session2, "secret_key", 10, pickle2, pickle_length
pickle2, pickle_length); );
assert_equals(pickle1, pickle2, pickle_length); assert_equals(pickle1, pickle2, pickle_length);
} }
......
...@@ -49,7 +49,9 @@ mock_random(ot_random, sizeof(ot_random)); ...@@ -49,7 +49,9 @@ mock_random(ot_random, sizeof(ot_random));
std::size_t pickle_length = ::olm_pickle_account_length(account); std::size_t pickle_length = ::olm_pickle_account_length(account);
std::uint8_t pickle1[pickle_length]; std::uint8_t pickle1[pickle_length];
::olm_pickle_account(account, "secret_key", 10, pickle1, pickle_length); std::size_t res = ::olm_pickle_account(account, "secret_key", 10, pickle1, pickle_length);
assert_equals(pickle_length, res);
std::uint8_t pickle2[pickle_length]; std::uint8_t pickle2[pickle_length];
std::memcpy(pickle2, pickle1, pickle_length); std::memcpy(pickle2, pickle1, pickle_length);
...@@ -59,10 +61,10 @@ assert_not_equals(std::size_t(-1), ::olm_unpickle_account( ...@@ -59,10 +61,10 @@ assert_not_equals(std::size_t(-1), ::olm_unpickle_account(
account2, "secret_key", 10, pickle2, pickle_length account2, "secret_key", 10, pickle2, pickle_length
)); ));
assert_equals(pickle_length, ::olm_pickle_account_length(account2)); assert_equals(pickle_length, ::olm_pickle_account_length(account2));
::olm_pickle_account(account2, "secret_key", 10, pickle2, pickle_length); res = ::olm_pickle_account(account2, "secret_key", 10, pickle2, pickle_length);
assert_equals(pickle_length, res);
assert_equals(pickle1, pickle2, pickle_length); assert_equals(pickle1, pickle2, pickle_length);
} }
...@@ -122,7 +124,9 @@ mock_random(random2, sizeof(random2)); ...@@ -122,7 +124,9 @@ mock_random(random2, sizeof(random2));
std::size_t pickle_length = ::olm_pickle_session_length(session); std::size_t pickle_length = ::olm_pickle_session_length(session);
std::uint8_t pickle1[pickle_length]; std::uint8_t pickle1[pickle_length];
::olm_pickle_session(session, "secret_key", 10, pickle1, pickle_length); std::size_t res = ::olm_pickle_session(session, "secret_key", 10, pickle1, pickle_length);
assert_equals(pickle_length, res);
std::uint8_t pickle2[pickle_length]; std::uint8_t pickle2[pickle_length];
std::memcpy(pickle2, pickle1, pickle_length); std::memcpy(pickle2, pickle1, pickle_length);
...@@ -132,10 +136,10 @@ assert_not_equals(std::size_t(-1), ::olm_unpickle_session( ...@@ -132,10 +136,10 @@ assert_not_equals(std::size_t(-1), ::olm_unpickle_session(
session2, "secret_key", 10, pickle2, pickle_length session2, "secret_key", 10, pickle2, pickle_length
)); ));
assert_equals(pickle_length, ::olm_pickle_session_length(session2)); assert_equals(pickle_length, ::olm_pickle_session_length(session2));
::olm_pickle_session(session2, "secret_key", 10, pickle2, pickle_length); res = ::olm_pickle_session(session2, "secret_key", 10, pickle2, pickle_length);
assert_equals(pickle_length, res);
assert_equals(pickle1, pickle2, pickle_length); assert_equals(pickle1, pickle2, pickle_length);
} }
{ /** Loopback test */ { /** Loopback test */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment