2018-12-28 15:04:05 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2019-01-13 14:00:50 +00:00
|
|
|
#include <crypto/crypto.hpp>
|
2018-12-28 15:04:05 +00:00
|
|
|
#include <router_contact.hpp>
|
|
|
|
|
2019-01-02 22:21:29 +00:00
|
|
|
static const byte_t DEF_VALUE[] = "unittest";
|
|
|
|
|
2018-12-28 15:04:05 +00:00
|
|
|
struct RCTest : public ::testing::Test
|
|
|
|
{
|
|
|
|
using RC_t = llarp::RouterContact;
|
|
|
|
using SecKey_t = llarp::SecretKey;
|
|
|
|
|
2019-01-05 00:49:06 +00:00
|
|
|
RCTest()
|
|
|
|
: crypto(llarp::Crypto::sodium{}), oldval(llarp::NetID::DefaultValue())
|
2018-12-28 15:04:05 +00:00
|
|
|
{
|
2019-01-05 00:49:06 +00:00
|
|
|
llarp::NetID::DefaultValue() = llarp::NetID(DEF_VALUE);
|
2018-12-28 15:04:05 +00:00
|
|
|
}
|
|
|
|
|
2019-01-02 22:21:29 +00:00
|
|
|
~RCTest()
|
2018-12-28 15:04:05 +00:00
|
|
|
{
|
2019-01-05 00:49:06 +00:00
|
|
|
llarp::NetID::DefaultValue() = oldval;
|
2018-12-28 15:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
llarp::Crypto crypto;
|
2019-01-05 00:49:06 +00:00
|
|
|
const llarp::NetID oldval;
|
2018-12-28 15:04:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(RCTest, TestSignVerify)
|
|
|
|
{
|
2019-01-17 15:11:17 +00:00
|
|
|
llarp::NetID netid(DEF_VALUE);
|
|
|
|
RC_t rc;
|
2018-12-28 15:04:05 +00:00
|
|
|
SecKey_t encr;
|
|
|
|
SecKey_t sign;
|
|
|
|
crypto.encryption_keygen(encr);
|
|
|
|
crypto.identity_keygen(sign);
|
2019-01-02 22:21:29 +00:00
|
|
|
rc.enckey = encr.toPublic();
|
2019-01-17 15:11:17 +00:00
|
|
|
rc.pubkey = sign.toPublic();
|
|
|
|
ASSERT_TRUE(rc.netID == netid);
|
|
|
|
ASSERT_TRUE(rc.netID == llarp::NetID::DefaultValue());
|
2018-12-28 15:04:05 +00:00
|
|
|
ASSERT_TRUE(rc.Sign(&crypto, sign));
|
|
|
|
ASSERT_TRUE(rc.Verify(&crypto, llarp::time_now_ms()));
|
|
|
|
}
|