lokinet/test/test_llarp_router_contact.cpp

45 lines
1.0 KiB
C++
Raw Normal View History

2018-12-28 15:04:05 +00:00
#include <gtest/gtest.h>
2019-01-13 14:00:50 +00:00
#include <crypto/crypto.hpp>
#include <crypto/crypto_libsodium.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;
RCTest() : 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::sodium::CryptoLibSodium 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;
2019-04-08 17:40:51 +00:00
2018-12-28 15:04:05 +00:00
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();
2019-04-08 17:40:51 +00:00
rc.exits.emplace_back(rc.pubkey, llarp::nuint32_t{50000});
2019-01-17 15:11:17 +00:00
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()));
}