aboutsummaryrefslogtreecommitdiff
path: root/tests/test_ratchet.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-06-12 09:08:15 +0100
committerMark Haines <mark.haines@matrix.org>2015-06-12 09:08:15 +0100
commit08a7e44a966047a10d7e959d4a8cdeaaf4139ce0 (patch)
tree8e80ff0b0ed3e93c3bcc575ead1f9ae1b1e34ff8 /tests/test_ratchet.cpp
parent793b9b910a8f3c010a55433188e4b63414cbb314 (diff)
Pass the message body to decrypt_max_plaintext_length so we can get a more accurate estimate, rename encrypt_max_output_length to encrypt_output_length and change the api to return the exact number of bytes needed to hold the message
Diffstat (limited to 'tests/test_ratchet.cpp')
-rw-r--r--tests/test_ratchet.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/tests/test_ratchet.cpp b/tests/test_ratchet.cpp
index e262bfa..e1a0519 100644
--- a/tests/test_ratchet.cpp
+++ b/tests/test_ratchet.cpp
@@ -54,13 +54,11 @@ std::size_t message_length, random_length, output_length;
std::size_t encrypt_length, decrypt_length;
{
/* Bob sends Alice a message */
- message_length = bob.encrypt_max_output_length(plaintext_length);
+ message_length = bob.encrypt_output_length(plaintext_length);
random_length = bob.encrypt_random_length();
assert_equals(std::size_t(0), random_length);
- output_length = alice.decrypt_max_plaintext_length(message_length);
std::uint8_t message[message_length];
- std::uint8_t output[output_length];
encrypt_length = bob.encrypt(
plaintext, plaintext_length,
@@ -69,6 +67,8 @@ std::size_t encrypt_length, decrypt_length;
);
assert_equals(message_length, encrypt_length);
+ output_length = alice.decrypt_max_plaintext_length(message, message_length);
+ std::uint8_t output[output_length];
decrypt_length = alice.decrypt(
message, message_length,
output, output_length
@@ -80,13 +80,11 @@ std::size_t encrypt_length, decrypt_length;
{
/* Alice sends Bob a message */
- message_length = alice.encrypt_max_output_length(plaintext_length);
+ message_length = alice.encrypt_output_length(plaintext_length);
random_length = alice.encrypt_random_length();
assert_equals(std::size_t(32), random_length);
- output_length = bob.decrypt_max_plaintext_length(message_length);
std::uint8_t message[message_length];
- std::uint8_t output[output_length];
std::uint8_t random[] = "This is a random 32 byte string.";
encrypt_length = alice.encrypt(
@@ -96,6 +94,8 @@ std::size_t encrypt_length, decrypt_length;
);
assert_equals(message_length, encrypt_length);
+ output_length = bob.decrypt_max_plaintext_length(message, message_length);
+ std::uint8_t output[output_length];
decrypt_length = bob.decrypt(
message, message_length,
output, output_length
@@ -127,7 +127,7 @@ std::size_t encrypt_length, decrypt_length;
{
/* Alice sends Bob two messages and they arrive out of order */
- message_1_length = alice.encrypt_max_output_length(plaintext_1_length);
+ message_1_length = alice.encrypt_output_length(plaintext_1_length);
random_length = alice.encrypt_random_length();
assert_equals(std::size_t(32), random_length);
@@ -140,7 +140,7 @@ std::size_t encrypt_length, decrypt_length;
);
assert_equals(message_1_length, encrypt_length);
- message_2_length = alice.encrypt_max_output_length(plaintext_2_length);
+ message_2_length = alice.encrypt_output_length(plaintext_2_length);
random_length = alice.encrypt_random_length();
assert_equals(std::size_t(0), random_length);
@@ -152,7 +152,9 @@ std::size_t encrypt_length, decrypt_length;
);
assert_equals(message_2_length, encrypt_length);
- output_length = bob.decrypt_max_plaintext_length(message_2_length);
+ output_length = bob.decrypt_max_plaintext_length(
+ message_2, message_2_length
+ );
std::uint8_t output_1[output_length];
decrypt_length = bob.decrypt(
message_2, message_2_length,
@@ -161,7 +163,9 @@ std::size_t encrypt_length, decrypt_length;
assert_equals(plaintext_2_length, decrypt_length);
assert_equals(plaintext_2, output_1, decrypt_length);
- output_length = bob.decrypt_max_plaintext_length(message_1_length);
+ output_length = bob.decrypt_max_plaintext_length(
+ message_1, message_1_length
+ );
std::uint8_t output_2[output_length];
decrypt_length = bob.decrypt(
message_1, message_1_length,