aboutsummaryrefslogtreecommitdiff
path: root/tests/test_olm.cpp
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2019-04-22 10:12:42 -0400
committerHubert Chathi <hubert@uhoreg.ca>2019-04-22 10:12:42 -0400
commitea13edcae00cc4ab1805e85322e73b7aa2faba7a (patch)
tree1960e726574ebcb8ce52230c0cc86ecce4833f91 /tests/test_olm.cpp
parent157c0fa67e1ccdaac5a66983004dab8e978f2b4f (diff)
don't use variable length or zero-length arrays in test files
as some compilers don't handle that
Diffstat (limited to 'tests/test_olm.cpp')
-rw-r--r--tests/test_olm.cpp366
1 files changed, 180 insertions, 186 deletions
diff --git a/tests/test_olm.cpp b/tests/test_olm.cpp
index b24cd90..ab7d816 100644
--- a/tests/test_olm.cpp
+++ b/tests/test_olm.cpp
@@ -4,6 +4,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
+#include <vector>
struct MockRandom {
MockRandom(std::uint8_t tag, std::uint8_t offset = 0)
@@ -36,35 +37,34 @@ TestCase test_case("Pickle account test");
MockRandom mock_random('P');
-std::uint8_t account_buffer[::olm_account_size()];
-::OlmAccount *account = ::olm_account(account_buffer);
-std::uint8_t random[::olm_create_account_random_length(account)];
-mock_random(random, sizeof(random));
-::olm_create_account(account, random, sizeof(random));
-std::uint8_t ot_random[::olm_account_generate_one_time_keys_random_length(
+std::vector<std::uint8_t> account_buffer(::olm_account_size());
+::OlmAccount *account = ::olm_account(account_buffer.data());
+std::vector<std::uint8_t> random(::olm_create_account_random_length(account));
+mock_random(random.data(), random.size());
+::olm_create_account(account, random.data(), random.size());
+std::vector<std::uint8_t> ot_random(::olm_account_generate_one_time_keys_random_length(
account, 42
-)];
-mock_random(ot_random, sizeof(ot_random));
-::olm_account_generate_one_time_keys(account, 42, ot_random, sizeof(ot_random));
+ ));
+mock_random(ot_random.data(), ot_random.size());
+::olm_account_generate_one_time_keys(account, 42, ot_random.data(), ot_random.size());
std::size_t pickle_length = ::olm_pickle_account_length(account);
-std::uint8_t pickle1[pickle_length];
-std::size_t res = ::olm_pickle_account(account, "secret_key", 10, pickle1, pickle_length);
+std::vector<std::uint8_t> pickle1(pickle_length);
+std::size_t res = ::olm_pickle_account(account, "secret_key", 10, pickle1.data(), pickle_length);
assert_equals(pickle_length, res);
-std::uint8_t pickle2[pickle_length];
-std::memcpy(pickle2, pickle1, pickle_length);
+std::vector<std::uint8_t> pickle2(pickle1);
-std::uint8_t account_buffer2[::olm_account_size()];
-::OlmAccount *account2 = ::olm_account(account_buffer2);
+std::vector<std::uint8_t> account_buffer2(::olm_account_size());
+::OlmAccount *account2 = ::olm_account(account_buffer2.data());
assert_not_equals(std::size_t(-1), ::olm_unpickle_account(
- account2, "secret_key", 10, pickle2, pickle_length
+ account2, "secret_key", 10, pickle2.data(), pickle_length
));
assert_equals(pickle_length, ::olm_pickle_account_length(account2));
-res = ::olm_pickle_account(account2, "secret_key", 10, pickle2, pickle_length);
+res = ::olm_pickle_account(account2, "secret_key", 10, pickle2.data(), pickle_length);
assert_equals(pickle_length, res);
-assert_equals(pickle1, pickle2, pickle_length);
+assert_equals(pickle1.data(), pickle2.data(), pickle_length);
}
@@ -79,8 +79,8 @@ assert_equals(pickle1, pickle2, pickle_length);
"K/A/8TOu9iK2hDFszy6xETiousHnHgh2ZGbRUh4pQx+YMm8ZdNZeRnwFGLnrWyf9"
"O5TmXua1FcU";
- std::uint8_t account_buffer[::olm_account_size()];
- ::OlmAccount *account = ::olm_account(account_buffer);
+ std::vector<std::uint8_t> account_buffer(::olm_account_size());
+ ::OlmAccount *account = ::olm_account(account_buffer.data());
assert_equals(
std::size_t(-1),
::olm_unpickle_account(
@@ -99,47 +99,46 @@ assert_equals(pickle1, pickle2, pickle_length);
TestCase test_case("Pickle session test");
MockRandom mock_random('P');
-std::uint8_t account_buffer[::olm_account_size()];
-::OlmAccount *account = ::olm_account(account_buffer);
-std::uint8_t random[::olm_create_account_random_length(account)];
-mock_random(random, sizeof(random));
-::olm_create_account(account, random, sizeof(random));
+std::vector<std::uint8_t> account_buffer(::olm_account_size());
+::OlmAccount *account = ::olm_account(account_buffer.data());
+std::vector<std::uint8_t> random(::olm_create_account_random_length(account));
+mock_random(random.data(), random.size());
+::olm_create_account(account, random.data(), random.size());
-std::uint8_t session_buffer[::olm_session_size()];
-::OlmSession *session = ::olm_session(session_buffer);
+std::vector<std::uint8_t> session_buffer(::olm_session_size());
+::OlmSession *session = ::olm_session(session_buffer.data());
std::uint8_t identity_key[32];
std::uint8_t one_time_key[32];
mock_random(identity_key, sizeof(identity_key));
mock_random(one_time_key, sizeof(one_time_key));
-std::uint8_t random2[::olm_create_outbound_session_random_length(session)];
-mock_random(random2, sizeof(random2));
+std::vector<std::uint8_t> random2(::olm_create_outbound_session_random_length(session));
+mock_random(random2.data(), random2.size());
::olm_create_outbound_session(
session, account,
identity_key, sizeof(identity_key),
one_time_key, sizeof(one_time_key),
- random2, sizeof(random2)
+ random2.data(), random2.size()
);
std::size_t pickle_length = ::olm_pickle_session_length(session);
-std::uint8_t pickle1[pickle_length];
-std::size_t res = ::olm_pickle_session(session, "secret_key", 10, pickle1, pickle_length);
+std::vector<std::uint8_t> pickle1(pickle_length);
+std::size_t res = ::olm_pickle_session(session, "secret_key", 10, pickle1.data(), pickle_length);
assert_equals(pickle_length, res);
-std::uint8_t pickle2[pickle_length];
-std::memcpy(pickle2, pickle1, pickle_length);
+std::vector<std::uint8_t> pickle2(pickle1);
-std::uint8_t session_buffer2[::olm_session_size()];
-::OlmSession *session2 = ::olm_session(session_buffer2);
+std::vector<std::uint8_t> session_buffer2(::olm_session_size());
+::OlmSession *session2 = ::olm_session(session_buffer2.data());
assert_not_equals(std::size_t(-1), ::olm_unpickle_session(
- session2, "secret_key", 10, pickle2, pickle_length
+ session2, "secret_key", 10, pickle2.data(), pickle_length
));
assert_equals(pickle_length, ::olm_pickle_session_length(session2));
-res = ::olm_pickle_session(session2, "secret_key", 10, pickle2, pickle_length);
+res = ::olm_pickle_session(session2, "secret_key", 10, pickle2.data(), pickle_length);
assert_equals(pickle_length, res);
-assert_equals(pickle1, pickle2, pickle_length);
+assert_equals(pickle1.data(), pickle2.data(), pickle_length);
}
{ /** Loopback test */
@@ -148,145 +147,143 @@ TestCase test_case("Loopback test");
MockRandom mock_random_a('A', 0x00);
MockRandom mock_random_b('B', 0x80);
-std::uint8_t a_account_buffer[::olm_account_size()];
-::OlmAccount *a_account = ::olm_account(a_account_buffer);
-std::uint8_t a_random[::olm_create_account_random_length(a_account)];
-mock_random_a(a_random, sizeof(a_random));
-::olm_create_account(a_account, a_random, sizeof(a_random));
-
-std::uint8_t b_account_buffer[::olm_account_size()];
-::OlmAccount *b_account = ::olm_account(b_account_buffer);
-std::uint8_t b_random[::olm_create_account_random_length(b_account)];
-mock_random_b(b_random, sizeof(b_random));
-::olm_create_account(b_account, b_random, sizeof(b_random));
-std::uint8_t o_random[::olm_account_generate_one_time_keys_random_length(
+std::vector<std::uint8_t> a_account_buffer(::olm_account_size());
+::OlmAccount *a_account = ::olm_account(a_account_buffer.data());
+std::vector<std::uint8_t> a_random(::olm_create_account_random_length(a_account));
+mock_random_a(a_random.data(), a_random.size());
+::olm_create_account(a_account, a_random.data(), a_random.size());
+
+std::vector<std::uint8_t> b_account_buffer(::olm_account_size());
+::OlmAccount *b_account = ::olm_account(b_account_buffer.data());
+std::vector<std::uint8_t> b_random(::olm_create_account_random_length(b_account));
+mock_random_b(b_random.data(), b_random.size());
+::olm_create_account(b_account, b_random.data(), b_random.size());
+std::vector<std::uint8_t> o_random(::olm_account_generate_one_time_keys_random_length(
b_account, 42
-)];
-mock_random_b(o_random, sizeof(o_random));
-::olm_account_generate_one_time_keys(b_account, 42, o_random, sizeof(o_random));
-
-std::uint8_t a_id_keys[::olm_account_identity_keys_length(a_account)];
-::olm_account_identity_keys(a_account, a_id_keys, sizeof(a_id_keys));
-
-std::uint8_t b_id_keys[::olm_account_identity_keys_length(b_account)];
-std::uint8_t b_ot_keys[::olm_account_one_time_keys_length(b_account)];
-::olm_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys));
-::olm_account_one_time_keys(b_account, b_ot_keys, sizeof(b_ot_keys));
-
-std::uint8_t a_session_buffer[::olm_session_size()];
-::OlmSession *a_session = ::olm_session(a_session_buffer);
-std::uint8_t a_rand[::olm_create_outbound_session_random_length(a_session)];
-mock_random_a(a_rand, sizeof(a_rand));
+));
+mock_random_b(o_random.data(), o_random.size());
+::olm_account_generate_one_time_keys(b_account, 42, o_random.data(), o_random.size());
+
+std::vector<std::uint8_t> a_id_keys(::olm_account_identity_keys_length(a_account));
+::olm_account_identity_keys(a_account, a_id_keys.data(), a_id_keys.size());
+
+std::vector<std::uint8_t> b_id_keys(::olm_account_identity_keys_length(b_account));
+std::vector<std::uint8_t> b_ot_keys(::olm_account_one_time_keys_length(b_account));
+::olm_account_identity_keys(b_account, b_id_keys.data(), b_id_keys.size());
+::olm_account_one_time_keys(b_account, b_ot_keys.data(), b_ot_keys.size());
+
+std::vector<std::uint8_t> a_session_buffer(::olm_session_size());
+::OlmSession *a_session = ::olm_session(a_session_buffer.data());
+std::vector<std::uint8_t> a_rand(::olm_create_outbound_session_random_length(a_session));
+mock_random_a(a_rand.data(), a_rand.size());
assert_not_equals(std::size_t(-1), ::olm_create_outbound_session(
a_session, a_account,
- b_id_keys + 15, 43, // B's curve25519 identity key
- b_ot_keys + 25, 43, // B's curve25519 one time key
- a_rand, sizeof(a_rand)
+ b_id_keys.data() + 15, 43, // B's curve25519 identity key
+ b_ot_keys.data() + 25, 43, // B's curve25519 one time key
+ a_rand.data(), a_rand.size()
));
std::uint8_t plaintext[] = "Hello, World";
-std::uint8_t message_1[::olm_encrypt_message_length(a_session, 12)];
-std::uint8_t a_message_random[::olm_encrypt_random_length(a_session)];
-mock_random_a(a_message_random, sizeof(a_message_random));
+std::vector<std::uint8_t> message_1(::olm_encrypt_message_length(a_session, 12));
+std::vector<std::uint8_t> a_message_random(::olm_encrypt_random_length(a_session));
+mock_random_a(a_message_random.data(), a_message_random.size());
assert_equals(std::size_t(0), ::olm_encrypt_message_type(a_session));
assert_not_equals(std::size_t(-1), ::olm_encrypt(
a_session,
plaintext, 12,
- a_message_random, sizeof(a_message_random),
- message_1, sizeof(message_1)
+ a_message_random.data(), a_message_random.size(),
+ message_1.data(), message_1.size()
));
-std::uint8_t tmp_message_1[sizeof(message_1)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t b_session_buffer[::olm_account_size()];
-::OlmSession *b_session = ::olm_session(b_session_buffer);
+std::vector<std::uint8_t> tmp_message_1(message_1);
+std::vector<std::uint8_t> b_session_buffer(::olm_account_size());
+::OlmSession *b_session = ::olm_session(b_session_buffer.data());
::olm_create_inbound_session(
- b_session, b_account, tmp_message_1, sizeof(message_1)
+ b_session, b_account, tmp_message_1.data(), message_1.size()
);
// Check that the inbound session matches the message it was created from.
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
assert_equals(std::size_t(1), ::olm_matches_inbound_session(
b_session,
- tmp_message_1, sizeof(message_1)
+ tmp_message_1.data(), message_1.size()
));
// Check that the inbound session matches the key this message is supposed
// to be from.
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
assert_equals(std::size_t(1), ::olm_matches_inbound_session_from(
b_session,
- a_id_keys + 15, 43, // A's curve125519 identity key.
- tmp_message_1, sizeof(message_1)
+ a_id_keys.data() + 15, 43, // A's curve125519 identity key.
+ tmp_message_1.data(), message_1.size()
));
// Check that the inbound session isn't from a different user.
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
assert_equals(std::size_t(0), ::olm_matches_inbound_session_from(
b_session,
- b_id_keys + 15, 43, // B's curve25519 identity key.
- tmp_message_1, sizeof(message_1)
+ b_id_keys.data() + 15, 43, // B's curve25519 identity key.
+ tmp_message_1.data(), message_1.size()
));
// Check that we can decrypt the message.
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t plaintext_1[::olm_decrypt_max_plaintext_length(
- b_session, 0, tmp_message_1, sizeof(message_1)
-)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
+std::vector<std::uint8_t> plaintext_1(::olm_decrypt_max_plaintext_length(
+ b_session, 0, tmp_message_1.data(), message_1.size()
+));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
assert_equals(std::size_t(12), ::olm_decrypt(
b_session, 0,
- tmp_message_1, sizeof(message_1),
- plaintext_1, sizeof(plaintext_1)
+ tmp_message_1.data(), message_1.size(),
+ plaintext_1.data(), plaintext_1.size()
));
-assert_equals(plaintext, plaintext_1, 12);
+assert_equals(plaintext, plaintext_1.data(), 12);
-std::uint8_t message_2[::olm_encrypt_message_length(b_session, 12)];
-std::uint8_t b_message_random[::olm_encrypt_random_length(b_session)];
-mock_random_b(b_message_random, sizeof(b_message_random));
+std::vector<std::uint8_t> message_2(::olm_encrypt_message_length(b_session, 12));
+std::vector<std::uint8_t> b_message_random(::olm_encrypt_random_length(b_session));
+mock_random_b(b_message_random.data(), b_message_random.size());
assert_equals(std::size_t(1), ::olm_encrypt_message_type(b_session));
assert_not_equals(std::size_t(-1), ::olm_encrypt(
b_session,
plaintext, 12,
- b_message_random, sizeof(b_message_random),
- message_2, sizeof(message_2)
+ b_message_random.data(), b_message_random.size(),
+ message_2.data(), message_2.size()
));
-std::uint8_t tmp_message_2[sizeof(message_2)];
-std::memcpy(tmp_message_2, message_2, sizeof(message_2));
-std::uint8_t plaintext_2[::olm_decrypt_max_plaintext_length(
- a_session, 1, tmp_message_2, sizeof(message_2)
-)];
-std::memcpy(tmp_message_2, message_2, sizeof(message_2));
+std::vector<std::uint8_t> tmp_message_2(message_2);
+std::vector<std::uint8_t> plaintext_2(::olm_decrypt_max_plaintext_length(
+ a_session, 1, tmp_message_2.data(), message_2.size()
+));
+std::memcpy(tmp_message_2.data(), message_2.data(), message_2.size());
assert_equals(std::size_t(12), ::olm_decrypt(
a_session, 1,
- tmp_message_2, sizeof(message_2),
- plaintext_2, sizeof(plaintext_2)
+ tmp_message_2.data(), message_2.size(),
+ plaintext_2.data(), plaintext_2.size()
));
-assert_equals(plaintext, plaintext_2, 12);
+assert_equals(plaintext, plaintext_2.data(), 12);
-std::memcpy(tmp_message_2, message_2, sizeof(message_2));
+std::memcpy(tmp_message_2.data(), message_2.data(), message_2.size());
assert_equals(std::size_t(-1), ::olm_decrypt(
a_session, 1,
- tmp_message_2, sizeof(message_2),
- plaintext_2, sizeof(plaintext_2)
+ tmp_message_2.data(), message_2.size(),
+ plaintext_2.data(), plaintext_2.size()
));
-std::uint8_t a_session_id[::olm_session_id_length(a_session)];
+std::vector<std::uint8_t> a_session_id(::olm_session_id_length(a_session));
assert_not_equals(std::size_t(-1), ::olm_session_id(
- a_session, a_session_id, sizeof(a_session_id)
+ a_session, a_session_id.data(), a_session_id.size()
));
-std::uint8_t b_session_id[::olm_session_id_length(b_session)];
+std::vector<std::uint8_t> b_session_id(::olm_session_id_length(b_session));
assert_not_equals(std::size_t(-1), ::olm_session_id(
- b_session, b_session_id, sizeof(b_session_id)
+ b_session, b_session_id.data(), b_session_id.size()
));
-assert_equals(sizeof(a_session_id), sizeof(b_session_id));
-assert_equals(a_session_id, b_session_id, sizeof(b_session_id));
+assert_equals(a_session_id.size(), b_session_id.size());
+assert_equals(a_session_id.data(), b_session_id.data(), b_session_id.size());
}
@@ -296,107 +293,104 @@ TestCase test_case("More messages test");
MockRandom mock_random_a('A', 0x00);
MockRandom mock_random_b('B', 0x80);
-std::uint8_t a_account_buffer[::olm_account_size()];
-::OlmAccount *a_account = ::olm_account(a_account_buffer);
-std::uint8_t a_random[::olm_create_account_random_length(a_account)];
-mock_random_a(a_random, sizeof(a_random));
-::olm_create_account(a_account, a_random, sizeof(a_random));
-
-std::uint8_t b_account_buffer[::olm_account_size()];
-::OlmAccount *b_account = ::olm_account(b_account_buffer);
-std::uint8_t b_random[::olm_create_account_random_length(b_account)];
-mock_random_b(b_random, sizeof(b_random));
-::olm_create_account(b_account, b_random, sizeof(b_random));
-std::uint8_t o_random[::olm_account_generate_one_time_keys_random_length(
+std::vector<std::uint8_t> a_account_buffer(::olm_account_size());
+::OlmAccount *a_account = ::olm_account(a_account_buffer.data());
+std::vector<std::uint8_t> a_random(::olm_create_account_random_length(a_account));
+mock_random_a(a_random.data(), a_random.size());
+::olm_create_account(a_account, a_random.data(), a_random.size());
+
+std::vector<std::uint8_t> b_account_buffer(::olm_account_size());
+::OlmAccount *b_account = ::olm_account(b_account_buffer.data());
+std::vector<std::uint8_t> b_random(::olm_create_account_random_length(b_account));
+mock_random_b(b_random.data(), b_random.size());
+::olm_create_account(b_account, b_random.data(), b_random.size());
+std::vector<std::uint8_t> o_random(::olm_account_generate_one_time_keys_random_length(
b_account, 42
-)];
-mock_random_b(o_random, sizeof(o_random));
-::olm_account_generate_one_time_keys(b_account, 42, o_random, sizeof(o_random));
-
-std::uint8_t b_id_keys[::olm_account_identity_keys_length(b_account)];
-std::uint8_t b_ot_keys[::olm_account_one_time_keys_length(b_account)];
-::olm_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys));
-::olm_account_one_time_keys(b_account, b_ot_keys, sizeof(b_ot_keys));
-
-std::uint8_t a_session_buffer[::olm_session_size()];
-::OlmSession *a_session = ::olm_session(a_session_buffer);
-std::uint8_t a_rand[::olm_create_outbound_session_random_length(a_session)];
-mock_random_a(a_rand, sizeof(a_rand));
+));
+mock_random_b(o_random.data(), o_random.size());
+::olm_account_generate_one_time_keys(b_account, 42, o_random.data(), o_random.size());
+
+std::vector<std::uint8_t> b_id_keys(::olm_account_identity_keys_length(b_account));
+std::vector<std::uint8_t> b_ot_keys(::olm_account_one_time_keys_length(b_account));
+::olm_account_identity_keys(b_account, b_id_keys.data(), b_id_keys.size());
+::olm_account_one_time_keys(b_account, b_ot_keys.data(), b_ot_keys.size());
+
+std::vector<std::uint8_t> a_session_buffer(::olm_session_size());
+::OlmSession *a_session = ::olm_session(a_session_buffer.data());
+std::vector<std::uint8_t> a_rand(::olm_create_outbound_session_random_length(a_session));
+mock_random_a(a_rand.data(), a_rand.size());
assert_not_equals(std::size_t(-1), ::olm_create_outbound_session(
a_session, a_account,
- b_id_keys + 15, 43,
- b_ot_keys + 25, 43,
- a_rand, sizeof(a_rand)
+ b_id_keys.data() + 15, 43,
+ b_ot_keys.data() + 25, 43,
+ a_rand.data(), a_rand.size()
));
std::uint8_t plaintext[] = "Hello, World";
-std::uint8_t message_1[::olm_encrypt_message_length(a_session, 12)];
-std::uint8_t a_message_random[::olm_encrypt_random_length(a_session)];
-mock_random_a(a_message_random, sizeof(a_message_random));
+std::vector<std::uint8_t> message_1(::olm_encrypt_message_length(a_session, 12));
+std::vector<std::uint8_t> a_message_random(::olm_encrypt_random_length(a_session));
+mock_random_a(a_message_random.data(), a_message_random.size());
assert_equals(std::size_t(0), ::olm_encrypt_message_type(a_session));
assert_not_equals(std::size_t(-1), ::olm_encrypt(
a_session,
plaintext, 12,
- a_message_random, sizeof(a_message_random),
- message_1, sizeof(message_1)
+ a_message_random.data(), a_message_random.size(),
+ message_1.data(), message_1.size()
));
-std::uint8_t tmp_message_1[sizeof(message_1)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t b_session_buffer[::olm_account_size()];
-::OlmSession *b_session = ::olm_session(b_session_buffer);
+std::vector<std::uint8_t> tmp_message_1(message_1);
+std::vector<std::uint8_t> b_session_buffer(::olm_account_size());
+::OlmSession *b_session = ::olm_session(b_session_buffer.data());
::olm_create_inbound_session(
- b_session, b_account, tmp_message_1, sizeof(message_1)
+ b_session, b_account, tmp_message_1.data(), message_1.size()
);
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
-std::uint8_t plaintext_1[::olm_decrypt_max_plaintext_length(
- b_session, 0, tmp_message_1, sizeof(message_1)
-)];
-std::memcpy(tmp_message_1, message_1, sizeof(message_1));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
+std::vector<std::uint8_t> plaintext_1(::olm_decrypt_max_plaintext_length(
+ b_session, 0, tmp_message_1.data(), message_1.size()
+));
+std::memcpy(tmp_message_1.data(), message_1.data(), message_1.size());
assert_equals(std::size_t(12), ::olm_decrypt(
b_session, 0,
- tmp_message_1, sizeof(message_1),
- plaintext_1, sizeof(plaintext_1)
+ tmp_message_1.data(), message_1.size(),
+ plaintext_1.data(), plaintext_1.size()
));
for (unsigned i = 0; i < 8; ++i) {
{
- std::uint8_t msg_a[::olm_encrypt_message_length(a_session, 12)];
- std::uint8_t rnd_a[::olm_encrypt_random_length(a_session)];
- mock_random_a(rnd_a, sizeof(rnd_a));
+ std::vector<std::uint8_t> msg_a(::olm_encrypt_message_length(a_session, 12));
+ std::vector<std::uint8_t> rnd_a(::olm_encrypt_random_length(a_session));
+ mock_random_a(rnd_a.data(), rnd_a.size());
std::size_t type_a = ::olm_encrypt_message_type(a_session);
assert_not_equals(std::size_t(-1), ::olm_encrypt(
- a_session, plaintext, 12, rnd_a, sizeof(rnd_a), msg_a, sizeof(msg_a)
+ a_session, plaintext, 12, rnd_a.data(), rnd_a.size(), msg_a.data(), msg_a.size()
));
- std::uint8_t tmp_a[sizeof(msg_a)];
- std::memcpy(tmp_a, msg_a, sizeof(msg_a));
- std::uint8_t out_a[::olm_decrypt_max_plaintext_length(
- b_session, type_a, tmp_a, sizeof(tmp_a)
- )];
- std::memcpy(tmp_a, msg_a, sizeof(msg_a));
+ std::vector<std::uint8_t> tmp_a(msg_a);
+ std::vector<std::uint8_t> out_a(::olm_decrypt_max_plaintext_length(
+ b_session, type_a, tmp_a.data(), tmp_a.size()
+ ));
+ std::memcpy(tmp_a.data(), msg_a.data(), sizeof(msg_a));
assert_equals(std::size_t(12), ::olm_decrypt(
- b_session, type_a, msg_a, sizeof(msg_a), out_a, sizeof(out_a)
+ b_session, type_a, msg_a.data(), msg_a.size(), out_a.data(), out_a.size()
));
}
{
- std::uint8_t msg_b[::olm_encrypt_message_length(b_session, 12)];
- std::uint8_t rnd_b[::olm_encrypt_random_length(b_session)];
- mock_random_b(rnd_b, sizeof(rnd_b));
+ std::vector<std::uint8_t> msg_b(::olm_encrypt_message_length(b_session, 12));
+ std::vector<std::uint8_t> rnd_b(::olm_encrypt_random_length(b_session));
+ mock_random_b(rnd_b.data(), rnd_b.size());
std::size_t type_b = ::olm_encrypt_message_type(b_session);
assert_not_equals(std::size_t(-1), ::olm_encrypt(
- b_session, plaintext, 12, rnd_b, sizeof(rnd_b), msg_b, sizeof(msg_b)
+ b_session, plaintext, 12, rnd_b.data(), rnd_b.size(), msg_b.data(), msg_b.size()
));
- std::uint8_t tmp_b[sizeof(msg_b)];
- std::memcpy(tmp_b, msg_b, sizeof(msg_b));
- std::uint8_t out_b[::olm_decrypt_max_plaintext_length(
- a_session, type_b, tmp_b, sizeof(tmp_b)
- )];
- std::memcpy(tmp_b, msg_b, sizeof(msg_b));
+ std::vector<std::uint8_t> tmp_b(msg_b);
+ std::vector<std::uint8_t> out_b(::olm_decrypt_max_plaintext_length(
+ a_session, type_b, tmp_b.data(), tmp_b.size()
+ ));
+ std::memcpy(tmp_b.data(), msg_b.data(), msg_b.size());
assert_equals(std::size_t(12), ::olm_decrypt(
- a_session, type_b, msg_b, sizeof(msg_b), out_b, sizeof(out_b)
+ a_session, type_b, msg_b.data(), msg_b.size(), out_b.data(), out_b.size()
));
}
}