Add Protocol::SignedMessage::valid + tests
This commit is contained in:
@@ -11,32 +11,26 @@ TEST_CASE("SignedMessage", "[protocol]") {
|
||||
crypto_sign_keypair(pub_key, priv_key);
|
||||
|
||||
auto msg = Protocol::SignedMessage(pub_key, priv_key, "Hello, world!");
|
||||
auto to_be_signed = msg.serialize();
|
||||
|
||||
SECTION("valid signed message") {
|
||||
REQUIRE(
|
||||
crypto_sign_verify_detached(msg.signature, to_be_signed.data(),
|
||||
to_be_signed.size(), pub_key) == 0);
|
||||
}
|
||||
SECTION("valid signed message") { REQUIRE(msg.valid(pub_key)); }
|
||||
|
||||
SECTION("tampered invalid signed message") {
|
||||
// todo: use to msg.valid()
|
||||
SECTION("plaintext") {
|
||||
msg.plaintext = "Hello, world111111";
|
||||
to_be_signed = msg.serialize();
|
||||
REQUIRE_FALSE(crypto_sign_verify_detached(
|
||||
msg.signature, to_be_signed.data(),
|
||||
to_be_signed.size(), pub_key) == 0);
|
||||
REQUIRE_FALSE(msg.valid(pub_key));
|
||||
}
|
||||
|
||||
SECTION("timestamp") {
|
||||
msg.timestamp = std::chrono::system_clock::now()
|
||||
.time_since_epoch()
|
||||
.count();
|
||||
to_be_signed = msg.serialize();
|
||||
REQUIRE_FALSE(crypto_sign_verify_detached(
|
||||
msg.signature, to_be_signed.data(),
|
||||
to_be_signed.size(), pub_key) == 0);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user