Merge from master

Merges the latest changes from master, having backed out the changes which
removed chain_index tracking, since they are still useful on this branch.
This commit is contained in:
Richard van der Hoff 2016-06-30 13:39:40 +01:00
commit 8b19ad3c8e
2 changed files with 28 additions and 16 deletions

View file

@ -381,7 +381,6 @@ std::size_t olm::pickle_length(
length += olm::pickle_length(value.sender_chain); length += olm::pickle_length(value.sender_chain);
length += olm::pickle_length(value.receiver_chains); length += olm::pickle_length(value.receiver_chains);
length += olm::pickle_length(value.skipped_message_keys); length += olm::pickle_length(value.skipped_message_keys);
length += olm::pickle_length(value.chain_index);
return length; return length;
} }
@ -393,7 +392,6 @@ std::uint8_t * olm::pickle(
pos = pickle(pos, value.sender_chain); pos = pickle(pos, value.sender_chain);
pos = pickle(pos, value.receiver_chains); pos = pickle(pos, value.receiver_chains);
pos = pickle(pos, value.skipped_message_keys); pos = pickle(pos, value.skipped_message_keys);
pos = pickle(pos, value.chain_index);
return pos; return pos;
} }
@ -406,7 +404,6 @@ std::uint8_t const * olm::unpickle(
pos = unpickle(pos, end, value.sender_chain); pos = unpickle(pos, end, value.sender_chain);
pos = unpickle(pos, end, value.receiver_chains); pos = unpickle(pos, end, value.receiver_chains);
pos = unpickle(pos, end, value.skipped_message_keys); pos = unpickle(pos, end, value.skipped_message_keys);
pos = unpickle(pos, end, value.chain_index);
return pos; return pos;
} }

View file

@ -1,11 +1,16 @@
#include "olm/olm.h" #include "olm/olm.h"
#include "unittest.hh" #include "unittest.hh"
const char * test_cases[] = { struct test_case {
"41776f", const char *msghex;
"7fff6f0101346d671201", const char *expected_error;
"ee776f41496f674177804177778041776f6716670a677d6f670a67c2677d", };
"e9e9c9c1e9e9c9e9c9c1e9e9c9c1",
const test_case test_cases[] = {
{ "41776f", "BAD_MESSAGE_FORMAT" },
{ "7fff6f0101346d671201", "BAD_MESSAGE_FORMAT" },
{ "ee776f41496f674177804177778041776f6716670a677d6f670a67c2677d", "BAD_MESSAGE_FORMAT" },
{ "e9e9c9c1e9e9c9e9c9c1e9e9c9c1", "BAD_MESSAGE_FORMAT" },
}; };
@ -31,29 +36,39 @@ void decode_hex(
} }
} }
void decrypt_case(int message_type, const char * test_case) { void decrypt_case(int message_type, const test_case * test_case) {
std::uint8_t session_memory[olm_session_size()]; std::uint8_t session_memory[olm_session_size()];
::OlmSession * session = ::olm_session(session_memory); ::OlmSession * session = ::olm_session(session_memory);
std::uint8_t pickled[strlen(session_data)]; std::uint8_t pickled[strlen(session_data)];
::memcpy(pickled, session_data, sizeof(pickled)); ::memcpy(pickled, session_data, sizeof(pickled));
::olm_unpickle_session(session, "", 0, pickled, sizeof(pickled)); assert_not_equals(
::olm_error(),
::olm_unpickle_session(session, "", 0, pickled, sizeof(pickled))
);
std::size_t message_length = strlen(test_case) / 2; std::size_t message_length = strlen(test_case->msghex) / 2;
std::uint8_t * message = (std::uint8_t *) ::malloc(message_length); std::uint8_t * message = (std::uint8_t *) ::malloc(message_length);
decode_hex(test_case, message, message_length); decode_hex(test_case->msghex, message, message_length);
size_t max_length = olm_decrypt_max_plaintext_length( size_t max_length = olm_decrypt_max_plaintext_length(
session, message_type, message, message_length session, message_type, message, message_length
); );
if (max_length == std::size_t(-1)) { if (test_case->expected_error) {
assert_equals(::olm_error(), max_length);
assert_equals(
std::string(test_case->expected_error),
std::string(::olm_session_last_error(session))
);
free(message); free(message);
return; return;
} }
assert_not_equals(::olm_error(), max_length);
uint8_t plaintext[max_length]; uint8_t plaintext[max_length];
decode_hex(test_case, message, message_length); decode_hex(test_case->msghex, message, message_length);
olm_decrypt( olm_decrypt(
session, message_type, session, message_type,
message, message_length, message, message_length,
@ -67,8 +82,8 @@ int main() {
{ {
TestCase my_test("Olm decrypt test"); TestCase my_test("Olm decrypt test");
for (unsigned int i = 0; i < sizeof(test_cases)/ sizeof(const char *); ++i) { for (unsigned int i = 0; i < sizeof(test_cases)/ sizeof(test_cases[0]); ++i) {
decrypt_case(0, test_cases[i]); decrypt_case(0, &test_cases[i]);
} }
} }