aboutsummaryrefslogtreecommitdiff
path: root/tests/test_olm_signature.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_olm_signature.cpp')
-rw-r--r--tests/test_olm_signature.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/test_olm_signature.cpp b/tests/test_olm_signature.cpp
new file mode 100644
index 0000000..a7cce63
--- /dev/null
+++ b/tests/test_olm_signature.cpp
@@ -0,0 +1,81 @@
+#include "olm/olm.hh"
+#include "unittest.hh"
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+struct MockRandom {
+ MockRandom(std::uint8_t tag, std::uint8_t offset = 0)
+ : tag(tag), current(offset) {}
+ void operator()(
+ void * buf, std::size_t length
+ ) {
+ std::uint8_t * bytes = (std::uint8_t *) buf;
+ while (length > 32) {
+ bytes[0] = tag;
+ std::memset(bytes + 1, current, 31);
+ length -= 32;
+ bytes += 32;
+ current += 1;
+ }
+ if (length) {
+ bytes[0] = tag;
+ std::memset(bytes + 1, current, length - 1);
+ current += 1;
+ }
+ }
+ std::uint8_t tag;
+ std::uint8_t current;
+};
+
+std::uint8_t * check_malloc(std::size_t size) {
+ if (size == std::size_t(-1)) {
+ assert_not_equals(std::size_t(-1), size);
+ }
+ return (std::uint8_t *)::malloc(size);
+}
+
+
+int main() {
+
+{ /** Signing Test */
+TestCase test_case("Signing test");
+
+MockRandom mock_random_a('A', 0x00);
+
+void * account_buffer = check_malloc(::olm_account_size());
+::OlmAccount * account = ::olm_account(account_buffer);
+
+std::size_t random_size = ::olm_create_account_random_length(account);
+void * random = check_malloc(random_size);
+mock_random_a(random, random_size);
+::olm_create_account(account, random, random_size);
+::free(random);
+
+std::size_t message_size = 12;
+void * message = check_malloc(message_size);
+::memcpy(message, "Hello, World", message_size);
+
+std::size_t signature_size = ::olm_account_signature_length(account);
+void * signature = check_malloc(signature_size);
+assert_not_equals(std::size_t(-1), ::olm_account_sign(
+ account, message, message_size, signature, signature_size
+));
+
+std::size_t id_keys_size = ::olm_account_identity_keys_length(account);
+std::uint8_t * id_keys = (std::uint8_t *) check_malloc(id_keys_size);
+assert_not_equals(std::size_t(-1), ::olm_account_identity_keys(
+ account, id_keys, id_keys_size
+));
+
+void * utility_buffer = check_malloc(::olm_utility_size());
+::OlmUtility * utility = ::olm_utility(utility_buffer);
+
+assert_not_equals(std::size_t(-1), ::olm_ed25519_verify(
+ utility, id_keys + 71, 43, message, message_size, signature, signature_size
+));
+
+}
+
+}