Add Protocol::SignedMessage struct (not done)
This commit is contained in:
@@ -1,6 +1,32 @@
|
||||
#include "sodium/crypto_sign.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <protocol/protocol.hxx>
|
||||
#include <sodium.h>
|
||||
|
||||
TEST_CASE("something", "[stun]") {
|
||||
SECTION("true") { REQUIRE(true); }
|
||||
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!");
|
||||
std::vector<uint8_t> toBeSigned;
|
||||
toBeSigned.reserve(sizeof(msg.sender_key_fingerprint) +
|
||||
msg.plaintext.size() + sizeof(msg.timestamp));
|
||||
|
||||
toBeSigned.insert(toBeSigned.cend(), msg.sender_key_fingerprint,
|
||||
msg.sender_key_fingerprint +
|
||||
sizeof(msg.sender_key_fingerprint));
|
||||
toBeSigned.insert(toBeSigned.cend(), msg.plaintext.data(),
|
||||
msg.plaintext.data() + msg.plaintext.length());
|
||||
auto timestamp_bytes = reinterpret_cast<const uint8_t *>(&msg.timestamp);
|
||||
toBeSigned.insert(toBeSigned.cend(), timestamp_bytes,
|
||||
timestamp_bytes + sizeof(msg.timestamp));
|
||||
|
||||
SECTION("signed message") {
|
||||
REQUIRE(crypto_sign_verify_detached(
|
||||
msg.sender_key_signature, toBeSigned.data(),
|
||||
toBeSigned.size(), pub_key) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user