diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_olm_sha256.cpp | 20 | ||||
-rw-r--r-- | tests/test_olm_signature.cpp | 81 |
2 files changed, 101 insertions, 0 deletions
diff --git a/tests/test_olm_sha256.cpp b/tests/test_olm_sha256.cpp new file mode 100644 index 0000000..fe5bf42 --- /dev/null +++ b/tests/test_olm_sha256.cpp @@ -0,0 +1,20 @@ +#include "olm/olm.hh" +#include "unittest.hh" + +int main() { +{ +TestCase("Olm sha256 test"); + + +std::uint8_t utility_buffer[::olm_utility_size()]; +::OlmUtility * utility = ::olm_utility(utility_buffer); + +assert_equals(std::size_t(43), ::olm_sha256_length(utility)); +std::uint8_t output[43]; +::olm_sha256(utility, "Hello, World", 12, output, 43); + +std::uint8_t expected_output[] = "A2daxT/5zRU1zMffzfosRYxSGDcfQY3BNvLRmsH76KU"; +assert_equals(output, expected_output, 43); + +} +} 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 +)); + +} + +} |