mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
moved Identity to separate file
This commit is contained in:
parent
d714d7fe6c
commit
d03adfd193
67
Identity.h
Normal file
67
Identity.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef IDENTITY_H__
|
||||
#define IDENTITY_H__
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <cryptopp/sha.h>
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace data
|
||||
{
|
||||
#pragma pack(1)
|
||||
|
||||
struct Identity
|
||||
{
|
||||
uint8_t publicKey[256];
|
||||
uint8_t signingKey[128];
|
||||
uint8_t certificate[3];
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
class IdentHash
|
||||
{
|
||||
public:
|
||||
|
||||
IdentHash (const uint8_t * hash) { memcpy (m_Hash, hash, 32); };
|
||||
IdentHash (const IdentHash& ) = default;
|
||||
IdentHash (IdentHash&& ) = default;
|
||||
IdentHash () = default;
|
||||
|
||||
IdentHash& operator= (const IdentHash& ) = default;
|
||||
IdentHash& operator= (IdentHash&& ) = default;
|
||||
|
||||
uint8_t * operator()() { return m_Hash; };
|
||||
const uint8_t * operator()() const { return m_Hash; };
|
||||
|
||||
operator uint8_t * () { return m_Hash; };
|
||||
operator const uint8_t * () const { return m_Hash; };
|
||||
|
||||
bool operator== (const IdentHash& other) const { return !memcmp (m_Hash, other.m_Hash, 32); };
|
||||
bool operator< (const IdentHash& other) const { return memcmp (m_Hash, other.m_Hash, 32) < 0; };
|
||||
|
||||
private:
|
||||
|
||||
uint8_t m_Hash[32];
|
||||
};
|
||||
|
||||
inline IdentHash CalculateIdentHash (const Identity& identity)
|
||||
{
|
||||
IdentHash hash;
|
||||
CryptoPP::SHA256().CalculateDigest((uint8_t *)hash, (uint8_t *)&identity, sizeof (Identity));
|
||||
return hash;
|
||||
};
|
||||
|
||||
class RoutingDestination
|
||||
{
|
||||
public:
|
||||
virtual const IdentHash& GetIdentHash () const = 0;
|
||||
virtual const uint8_t * GetEncryptionPublicKey () const = 0;
|
||||
virtual bool IsDestination () const = 0; // for garlic
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,4 +1,3 @@
|
||||
#include <cryptopp/sha.h>
|
||||
#include "Log.h"
|
||||
#include "LeaseSet.h"
|
||||
|
||||
@ -6,6 +5,7 @@ namespace i2p
|
||||
{
|
||||
namespace data
|
||||
{
|
||||
|
||||
LeaseSet::LeaseSet (const uint8_t * buf, int len)
|
||||
{
|
||||
#pragma pack(1)
|
||||
@ -19,7 +19,8 @@ namespace data
|
||||
#pragma pack ()
|
||||
|
||||
const H * header = (const H *)buf;
|
||||
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&header->destination, sizeof (Identity));
|
||||
m_Identity = header->destination;
|
||||
m_IdentHash = CalculateIdentHash (m_Identity);
|
||||
memcpy (m_EncryptionKey, header->encryptionKey, 256);
|
||||
LogPrint ("LeaseSet num=", (int)header->num);
|
||||
|
||||
|
44
LeaseSet.h
44
LeaseSet.h
@ -4,6 +4,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <list>
|
||||
#include "Identity.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
@ -12,13 +13,6 @@ namespace data
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct Identity
|
||||
{
|
||||
uint8_t publicKey[256];
|
||||
uint8_t signingKey[128];
|
||||
uint8_t certificate[3];
|
||||
};
|
||||
|
||||
struct Lease
|
||||
{
|
||||
uint8_t tunnelGateway[32];
|
||||
@ -28,40 +22,6 @@ namespace data
|
||||
|
||||
#pragma pack()
|
||||
|
||||
class IdentHash
|
||||
{
|
||||
public:
|
||||
|
||||
IdentHash (const uint8_t * hash) { memcpy (m_Hash, hash, 32); };
|
||||
IdentHash (const IdentHash& ) = default;
|
||||
IdentHash (IdentHash&& ) = default;
|
||||
IdentHash () = default;
|
||||
|
||||
IdentHash& operator= (const IdentHash& ) = default;
|
||||
IdentHash& operator= (IdentHash&& ) = default;
|
||||
|
||||
uint8_t * operator()() { return m_Hash; };
|
||||
const uint8_t * operator()() const { return m_Hash; };
|
||||
|
||||
operator uint8_t * () { return m_Hash; };
|
||||
operator const uint8_t * () const { return m_Hash; };
|
||||
|
||||
bool operator== (const IdentHash& other) const { return !memcmp (m_Hash, other.m_Hash, 32); };
|
||||
bool operator< (const IdentHash& other) const { return memcmp (m_Hash, other.m_Hash, 32) < 0; };
|
||||
|
||||
private:
|
||||
|
||||
uint8_t m_Hash[32];
|
||||
};
|
||||
|
||||
class RoutingDestination // TODO: move to separate file later
|
||||
{
|
||||
public:
|
||||
virtual const IdentHash& GetIdentHash () const = 0;
|
||||
virtual const uint8_t * GetEncryptionPublicKey () const = 0;
|
||||
virtual bool IsDestination () const = 0; // for garlic
|
||||
};
|
||||
|
||||
class LeaseSet: public RoutingDestination
|
||||
{
|
||||
public:
|
||||
@ -69,6 +29,7 @@ namespace data
|
||||
LeaseSet (const uint8_t * buf, int len);
|
||||
|
||||
// implements RoutingDestination
|
||||
const Identity& GetIdentity () const { return m_Identity; };
|
||||
const IdentHash& GetIdentHash () const { return m_IdentHash; };
|
||||
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };
|
||||
bool IsDestination () const { return true; };
|
||||
@ -76,6 +37,7 @@ namespace data
|
||||
private:
|
||||
|
||||
std::list<Lease> m_Leases;
|
||||
Identity m_Identity;
|
||||
IdentHash m_IdentHash;
|
||||
uint8_t m_EncryptionKey[256];
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ namespace data
|
||||
void RouterInfo::SetRouterIdentity (const Identity& identity)
|
||||
{
|
||||
m_RouterIdentity = identity;
|
||||
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity));
|
||||
m_IdentHash = CalculateIdentHash (m_RouterIdentity);
|
||||
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user