mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-05 21:20:38 +00:00
43 lines
977 B
C++
43 lines
977 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <crypto/crypto.hpp>
|
|
#include <crypto/crypto_libsodium.hpp>
|
|
#include <router_contact.hpp>
|
|
|
|
static const byte_t DEF_VALUE[] = "unittest";
|
|
|
|
struct RCTest : public ::testing::Test
|
|
{
|
|
using RC_t = llarp::RouterContact;
|
|
using SecKey_t = llarp::SecretKey;
|
|
|
|
RCTest() : oldval(llarp::NetID::DefaultValue())
|
|
{
|
|
llarp::NetID::DefaultValue() = llarp::NetID(DEF_VALUE);
|
|
}
|
|
|
|
~RCTest()
|
|
{
|
|
llarp::NetID::DefaultValue() = oldval;
|
|
}
|
|
|
|
llarp::sodium::CryptoLibSodium crypto;
|
|
const llarp::NetID oldval;
|
|
};
|
|
|
|
TEST_F(RCTest, TestSignVerify)
|
|
{
|
|
llarp::NetID netid(DEF_VALUE);
|
|
RC_t rc;
|
|
SecKey_t encr;
|
|
SecKey_t sign;
|
|
crypto.encryption_keygen(encr);
|
|
crypto.identity_keygen(sign);
|
|
rc.enckey = encr.toPublic();
|
|
rc.pubkey = sign.toPublic();
|
|
ASSERT_TRUE(rc.netID == netid);
|
|
ASSERT_TRUE(rc.netID == llarp::NetID::DefaultValue());
|
|
ASSERT_TRUE(rc.Sign(&crypto, sign));
|
|
ASSERT_TRUE(rc.Verify(&crypto, llarp::time_now_ms()));
|
|
}
|