diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 18 | ||||
-rw-r--r-- | tests/test_sas.cpp | 55 |
2 files changed, 42 insertions, 31 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 12aaac4..332da12 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,6 @@ enable_testing() -foreach(test IN ITEMS +set(TEST_LIST test_base64 test_crypto test_group_session @@ -12,10 +12,20 @@ foreach(test IN ITEMS test_olm_sha256 test_olm_signature test_olm_using_malloc - test_ratchet test_session test_pk - ) + test_sas + ) + +if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND BUILD_SHARED_LIBS)) + # test_ratchet doesn't work on Windows when building a DLL, because it tries + # to use internal symbols, so only enable it if we're not on Windows, or if + # we're building statically + set(TEST_LIST ${TEST_LIST} test_ratchet) + add_test(Ratchet test_ratchet) +endif() + +foreach(test IN ITEMS ${TEST_LIST}) add_executable(${test} ${test}.cpp) target_include_directories(${test} PRIVATE include) target_link_libraries(${test} Olm::Olm) @@ -32,6 +42,6 @@ add_test(OlmDecrypt test_olm_decrypt) add_test(OlmSha256 test_olm_sha256) add_test(OlmSignature test_olm_signature) add_test(OlmUsingMalloc test_olm_using_malloc) -add_test(Ratchet test_ratchet) add_test(Session test_session) add_test(PublicKey test_session) +add_test(SAS test_sas) diff --git a/tests/test_sas.cpp b/tests/test_sas.cpp index 3578244..48b9ee6 100644 --- a/tests/test_sas.cpp +++ b/tests/test_sas.cpp @@ -5,6 +5,7 @@ #include "unittest.hh" #include <iostream> +#include <vector> int main() { @@ -31,26 +32,26 @@ std::uint8_t bob_private[32] = { const std::uint8_t *bob_public = (std::uint8_t *) "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08"; -std::uint8_t alice_sas_buffer[olm_sas_size()]; -OlmSAS *alice_sas = olm_sas(alice_sas_buffer); +std::vector<std::uint8_t> alice_sas_buffer(olm_sas_size()); +OlmSAS *alice_sas = olm_sas(alice_sas_buffer.data()); olm_create_sas(alice_sas, alice_private, sizeof(alice_private)); -std::uint8_t bob_sas_buffer[olm_sas_size()]; -OlmSAS *bob_sas = olm_sas(bob_sas_buffer); +std::vector<std::uint8_t> bob_sas_buffer(olm_sas_size()); +OlmSAS *bob_sas = olm_sas(bob_sas_buffer.data()); olm_create_sas(bob_sas, bob_private, sizeof(bob_private)); -std::uint8_t pubkey[::olm_sas_pubkey_length(alice_sas)]; +std::vector<std::uint8_t> pubkey(::olm_sas_pubkey_length(alice_sas)); -olm_sas_get_pubkey(alice_sas, pubkey, sizeof(pubkey)); +olm_sas_get_pubkey(alice_sas, pubkey.data(), pubkey.size()); -assert_equals(alice_public, pubkey, olm_sas_pubkey_length(alice_sas)); +assert_equals(alice_public, pubkey.data(), olm_sas_pubkey_length(alice_sas)); -olm_sas_set_their_key(bob_sas, pubkey, olm_sas_pubkey_length(bob_sas)); +olm_sas_set_their_key(bob_sas, pubkey.data(), olm_sas_pubkey_length(bob_sas)); -olm_sas_get_pubkey(bob_sas, pubkey, sizeof(pubkey)); +olm_sas_get_pubkey(bob_sas, pubkey.data(), pubkey.size()); -assert_equals(bob_public, pubkey, olm_sas_pubkey_length(bob_sas)); +assert_equals(bob_public, pubkey.data(), olm_sas_pubkey_length(bob_sas)); -olm_sas_set_their_key(alice_sas, pubkey, olm_sas_pubkey_length(alice_sas)); +olm_sas_set_their_key(alice_sas, pubkey.data(), olm_sas_pubkey_length(alice_sas)); std::uint8_t alice_bytes[6]; std::uint8_t bob_bytes[6]; @@ -84,34 +85,34 @@ std::uint8_t bob_private[32] = { const std::uint8_t *bob_public = (std::uint8_t *) "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08"; -std::uint8_t alice_sas_buffer[olm_sas_size()]; -OlmSAS *alice_sas = olm_sas(alice_sas_buffer); +std::vector<std::uint8_t> alice_sas_buffer(olm_sas_size()); +OlmSAS *alice_sas = olm_sas(alice_sas_buffer.data()); olm_create_sas(alice_sas, alice_private, sizeof(alice_private)); -std::uint8_t bob_sas_buffer[olm_sas_size()]; -OlmSAS *bob_sas = olm_sas(bob_sas_buffer); +std::vector<std::uint8_t> bob_sas_buffer(olm_sas_size()); +OlmSAS *bob_sas = olm_sas(bob_sas_buffer.data()); olm_create_sas(bob_sas, bob_private, sizeof(bob_private)); -std::uint8_t pubkey[::olm_sas_pubkey_length(alice_sas)]; +std::vector<std::uint8_t> pubkey(::olm_sas_pubkey_length(alice_sas)); -olm_sas_get_pubkey(alice_sas, pubkey, sizeof(pubkey)); +olm_sas_get_pubkey(alice_sas, pubkey.data(), pubkey.size()); -assert_equals(alice_public, pubkey, olm_sas_pubkey_length(alice_sas)); +assert_equals(alice_public, pubkey.data(), olm_sas_pubkey_length(alice_sas)); -olm_sas_set_their_key(bob_sas, pubkey, olm_sas_pubkey_length(bob_sas)); +olm_sas_set_their_key(bob_sas, pubkey.data(), olm_sas_pubkey_length(bob_sas)); -olm_sas_get_pubkey(bob_sas, pubkey, sizeof(pubkey)); +olm_sas_get_pubkey(bob_sas, pubkey.data(), pubkey.size()); -assert_equals(bob_public, pubkey, olm_sas_pubkey_length(bob_sas)); +assert_equals(bob_public, pubkey.data(), olm_sas_pubkey_length(bob_sas)); -olm_sas_set_their_key(alice_sas, pubkey, olm_sas_pubkey_length(alice_sas)); +olm_sas_set_their_key(alice_sas, pubkey.data(), olm_sas_pubkey_length(alice_sas)); -std::uint8_t alice_mac[olm_sas_mac_length(alice_sas)]; -std::uint8_t bob_mac[olm_sas_mac_length(bob_sas)]; +std::vector<std::uint8_t> alice_mac(olm_sas_mac_length(alice_sas)); +std::vector<std::uint8_t> bob_mac(olm_sas_mac_length(bob_sas)); -olm_sas_calculate_mac(alice_sas, (void *) "Hello world!", 12, "MAC", 3, alice_mac, olm_sas_mac_length(alice_sas)); -olm_sas_calculate_mac(bob_sas, (void *) "Hello world!", 12, "MAC", 3, bob_mac, olm_sas_mac_length(bob_sas)); +olm_sas_calculate_mac(alice_sas, (void *) "Hello world!", 12, "MAC", 3, alice_mac.data(), olm_sas_mac_length(alice_sas)); +olm_sas_calculate_mac(bob_sas, (void *) "Hello world!", 12, "MAC", 3, bob_mac.data(), olm_sas_mac_length(bob_sas)); -assert_equals(alice_mac, bob_mac, olm_sas_mac_length(alice_sas)); +assert_equals(alice_mac.data(), bob_mac.data(), olm_sas_mac_length(alice_sas)); } } |