#include "sodium/crypto_sign.h" #include #include #include TEST_CASE("SignedMessage", "[protocol]") { 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!"); SECTION("valid signed message") { REQUIRE(msg.valid(pub_key)); } SECTION("tampered invalid signed message") { SECTION("plaintext") { msg.plaintext = "Hello, world111111"; REQUIRE_FALSE(msg.valid(pub_key)); } SECTION("timestamp") { msg.timestamp = std::chrono::system_clock::now() .time_since_epoch() .count(); REQUIRE_FALSE(msg.valid(pub_key)); } SECTION("fingerprint") { std::memset(msg.sender_key_fingerprint, 'H', crypto_hash_sha256_BYTES); REQUIRE_FALSE(msg.valid(pub_key)); } } }