22 lines
738 B
C++
22 lines
738 B
C++
#include "sodium/crypto_sign.h"
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <protocol/protocol.hxx>
|
|
#include <sodium.h>
|
|
|
|
TEST_CASE("SignedMessage", "[protocol]") {
|
|
SECTION("sodium init") REQUIRE(sodium_init() >= 0);
|
|
|
|
unsigned char pub_key[crypto_sign_PUBLICKEYBYTES];
|
|
unsigned char priv_key[crypto_sign_SECRETKEYBYTES];
|
|
crypto_sign_keypair(pub_key, priv_key);
|
|
|
|
auto msg = Protocol::SignedMessage(pub_key, priv_key, "Hello, world!");
|
|
auto to_be_signed = msg.serialize();
|
|
|
|
SECTION("signed message") {
|
|
REQUIRE(
|
|
crypto_sign_verify_detached(msg.signature, to_be_signed.data(),
|
|
to_be_signed.size(), pub_key) == 0);
|
|
}
|
|
}
|