You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/test/test_llarp_router_contact.cpp

43 lines
977 B
C++

6 years ago
#include <gtest/gtest.h>
#include <crypto/crypto.hpp>
#include <crypto/crypto_libsodium.hpp>
6 years ago
#include <router_contact.hpp>
static const byte_t DEF_VALUE[] = "unittest";
6 years ago
struct RCTest : public ::testing::Test
{
using RC_t = llarp::RouterContact;
using SecKey_t = llarp::SecretKey;
RCTest() : oldval(llarp::NetID::DefaultValue())
6 years ago
{
llarp::NetID::DefaultValue() = llarp::NetID(DEF_VALUE);
6 years ago
}
~RCTest()
6 years ago
{
llarp::NetID::DefaultValue() = oldval;
6 years ago
}
llarp::sodium::CryptoLibSodium crypto;
const llarp::NetID oldval;
6 years ago
};
TEST_F(RCTest, TestSignVerify)
{
llarp::NetID netid(DEF_VALUE);
RC_t rc;
6 years ago
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());
6 years ago
ASSERT_TRUE(rc.Sign(&crypto, sign));
ASSERT_TRUE(rc.Verify(&crypto, llarp::time_now_ms()));
}