]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Fix some test
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 7 Aug 2024 14:02:01 +0000 (15:02 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 7 Aug 2024 14:02:01 +0000 (15:02 +0100)
test/rspamd_cxx_unit_cryptobox.hxx

index b23cd138aaa8135e31de97bfffe247f38fae7751..feed5bbe3598d6b2f7fb607b2d3490508b95c7c7 100644 (file)
@@ -116,7 +116,28 @@ TEST_SUITE("rspamd_cryptobox")
        }
 
 
-       TEST_CASE("rspamd_cryptobox_encrypt_inplace")
+       TEST_CASE("rspamd_cryptobox_encrypt_inplace_25519")
+       {
+               unsigned char data[256];
+               gsize len = sizeof(data);
+               rspamd_nonce_t nonce;
+               rspamd_pk_t pk;
+               rspamd_sk_t sk;
+               rspamd_mac_t sig;
+               enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
+
+               ottery_rand_bytes(nonce, sizeof(nonce));
+
+               rspamd_cryptobox_keypair(pk, sk, mode);
+
+               memset(sig, 0, sizeof(sig));
+
+               rspamd_cryptobox_encrypt_inplace(data, len, nonce, pk, sk, sig, mode);
+
+               CHECK(rspamd_cryptobox_decrypt_inplace(data, len, nonce, pk, sk, sig, mode));
+       }
+
+       TEST_CASE("rspamd_cryptobox_encrypt_inplace_p256")
        {
                unsigned char data[256];
                gsize len = sizeof(data);
@@ -137,21 +158,39 @@ TEST_SUITE("rspamd_cryptobox")
                CHECK(rspamd_cryptobox_decrypt_inplace(data, len, nonce, pk, sk, sig, mode));
        }
 
+       TEST_CASE("rspamd_cryptobox_sign_25519")
+       {
+               enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
+               rspamd_sk_t sk;
+               rspamd_pk_t pk;
+               unsigned char sig[256];
+               unsigned long long siglen;
+               std::string m{"data to be signed"};
+
+               rspamd_cryptobox_keypair(pk, sk, mode);
+
+               rspamd_cryptobox_sign(sig, &siglen,
+                                                         reinterpret_cast<const unsigned char *>(m.data()), m.size(), sk, mode);
+               bool check_result = rspamd_cryptobox_verify(sig, siglen,
+                                                                                                       reinterpret_cast<const unsigned char *>(m.data()), m.size(), pk, mode);
+               CHECK(check_result == true);
+       }
 
-       TEST_CASE("rspamd_cryptobox_sign")
+       TEST_CASE("rspamd_cryptobox_sign_nist")
        {
                enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_NIST;
                rspamd_sk_t sk;
                rspamd_pk_t pk;
                unsigned char sig[256];
                unsigned long long siglen;
-               const unsigned char m[] = "data to be signed";
-               size_t mlen = strlen((const char *) m);
+               std::string m{"data to be signed"};
 
                rspamd_cryptobox_keypair(pk, sk, mode);
 
-               rspamd_cryptobox_sign(sig, &siglen, m, mlen, sk, mode);
-               bool check_result = rspamd_cryptobox_verify(sig, siglen, m, mlen, pk, mode);
+               rspamd_cryptobox_sign(sig, &siglen,
+                                                         reinterpret_cast<const unsigned char *>(m.data()), m.size(), sk, mode);
+               bool check_result = rspamd_cryptobox_verify(sig, siglen,
+                                                                                                       reinterpret_cast<const unsigned char *>(m.data()), m.size(), pk, mode);
                CHECK(check_result == true);
        }
 }