aboutsummaryrefslogtreecommitdiff
path: root/tests/test_pk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_pk.cpp')
-rw-r--r--tests/test_pk.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_pk.cpp b/tests/test_pk.cpp
index dcb412a..ab1f477 100644
--- a/tests/test_pk.cpp
+++ b/tests/test_pk.cpp
@@ -87,4 +87,75 @@ free(plaintext_buffer);
}
+{ /* Encryption Test Case 1 */
+
+TestCase test_case("Public Key Decryption pickling");
+
+std::uint8_t decryption_buffer[olm_pk_decryption_size()];
+OlmPkDecryption *decryption = olm_pk_decryption(decryption_buffer);
+
+std::uint8_t alice_private[32] = {
+ 0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
+ 0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
+ 0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
+ 0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
+};
+
+const std::uint8_t *alice_public = (std::uint8_t *) "hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmoK";
+
+std::uint8_t pubkey[olm_pk_key_length()];
+
+olm_pk_generate_key(
+ decryption,
+ pubkey, sizeof(pubkey),
+ alice_private, sizeof(alice_private)
+);
+
+const uint8_t *PICKLE_KEY=(uint8_t *)"secret_key";
+std::uint8_t pickle_buffer[olm_pickle_pk_decryption_length(decryption)];
+const uint8_t *expected_pickle = (uint8_t *) "qx37WTQrjZLz5tId/uBX9B3/okqAbV1ofl9UnHKno1eipByCpXleAAlAZoJgYnCDOQZDQWzo3luTSfkF9pU1mOILCbbouubs6TVeDyPfgGD9i86J8irHjA";
+
+olm_pickle_pk_decryption(
+ decryption,
+ PICKLE_KEY, strlen((char *)PICKLE_KEY),
+ pickle_buffer, sizeof(pickle_buffer)
+);
+assert_equals(expected_pickle, pickle_buffer, olm_pickle_pk_decryption_length(decryption));
+
+olm_clear_pk_decryption(decryption);
+
+memset(pubkey, 0, olm_pk_key_length());
+
+olm_unpickle_pk_decryption(
+ decryption,
+ PICKLE_KEY, strlen((char *)PICKLE_KEY),
+ pickle_buffer, sizeof(pickle_buffer),
+ pubkey, sizeof(pubkey)
+);
+
+assert_equals(alice_public, pubkey, olm_pk_key_length());
+
+char *ciphertext = strdup("ntk49j/KozVFtSqJXhCejg");
+const char *mac = "zpzU6BkZcNI";
+const char *ephemeral_key = "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08";
+
+size_t max_plaintext_length = olm_pk_max_plaintext_length(decryption, strlen(ciphertext));
+std::uint8_t *plaintext_buffer = (std::uint8_t *) malloc(max_plaintext_length);
+
+olm_pk_decrypt(
+ decryption,
+ ephemeral_key, strlen(ephemeral_key),
+ mac, strlen(mac),
+ ciphertext, strlen(ciphertext),
+ plaintext_buffer, max_plaintext_length
+);
+
+const std::uint8_t *plaintext = (std::uint8_t *) "This is a test";
+
+assert_equals(plaintext, plaintext_buffer, strlen((const char *)plaintext));
+
+free(ciphertext);
+free(plaintext_buffer);
+
+}
}