diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-09 13:10:35 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-09 13:10:35 +0100 |
commit | 0d45433cf182b5125eca024ec3e60ffbad68310f (patch) | |
tree | a3b7523dfdaebda587b0ac4d718cd784a97058f6 /test | |
parent | b83fb594e7665008f6f127d003765ed9efd23249 (diff) | |
download | rspamd-0d45433cf182b5125eca024ec3e60ffbad68310f.tar.gz rspamd-0d45433cf182b5125eca024ec3e60ffbad68310f.zip |
[Test] Add test for keypairs encrypt/decrypt
Diffstat (limited to 'test')
-rw-r--r-- | test/rspamd_cxx_unit_cryptobox.hxx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/rspamd_cxx_unit_cryptobox.hxx b/test/rspamd_cxx_unit_cryptobox.hxx index 3f3cab697..5829b1e43 100644 --- a/test/rspamd_cxx_unit_cryptobox.hxx +++ b/test/rspamd_cxx_unit_cryptobox.hxx @@ -20,6 +20,7 @@ #define RSPAMD_RSPAMD_CXX_UNIT_CRYPTOBOX_HXX #include "libcryptobox/cryptobox.h" #include <string> +#include <string_view> TEST_SUITE("rspamd_cryptobox") { @@ -151,6 +152,31 @@ TEST_SUITE("rspamd_cryptobox") pk); CHECK(check_result == true); } + + TEST_CASE("rspamd_keypair_encryption") + { + auto *kp = rspamd_keypair_new(RSPAMD_KEYPAIR_KEX); + std::string data{"data to be encrypted"}; + unsigned char *out; + gsize outlen; + GError *err = nullptr; + + auto ret = rspamd_keypair_encrypt(kp, reinterpret_cast<const unsigned char *>(data.data()), data.size(), + &out, &outlen, &err); + CHECK(ret); + CHECK(err == nullptr); + + unsigned char *decrypted; + gsize decrypted_len; + ret = rspamd_keypair_decrypt(kp, out, outlen, &decrypted, &decrypted_len, &err); + CHECK(ret); + CHECK(err == nullptr); + CHECK(decrypted_len == data.size()); + CHECK(data == std::string_view{reinterpret_cast<const char *>(decrypted), decrypted_len}); + + g_free(out); + g_free(decrypted); + } } #endif |