|
|
|
@ -9,7 +9,41 @@ namespace i2p
@@ -9,7 +9,41 @@ namespace i2p
|
|
|
|
|
{ |
|
|
|
|
namespace data |
|
|
|
|
{ |
|
|
|
|
class IdentHash; |
|
|
|
|
template<int sz> |
|
|
|
|
class Tag |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
Tag (const uint8_t * buf) { memcpy (m_Buf, buf, sz); }; |
|
|
|
|
Tag (const Tag<sz>& ) = default; |
|
|
|
|
#ifndef _WIN32 // FIXME!!! msvs 2013 can't compile it
|
|
|
|
|
Tag (Tag<sz>&& ) = default; |
|
|
|
|
#endif |
|
|
|
|
Tag () = default; |
|
|
|
|
|
|
|
|
|
Tag<sz>& operator= (const Tag<sz>& ) = default; |
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
Tag<sz>& operator= (Tag<sz>&& ) = default; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
uint8_t * operator()() { return m_Buf; }; |
|
|
|
|
const uint8_t * operator()() const { return m_Buf; }; |
|
|
|
|
|
|
|
|
|
operator uint8_t * () { return m_Buf; }; |
|
|
|
|
operator const uint8_t * () const { return m_Buf; }; |
|
|
|
|
|
|
|
|
|
bool operator== (const Tag<sz>& other) const { return !memcmp (m_Buf, other.m_Buf, sz); }; |
|
|
|
|
bool operator< (const Tag<sz>& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; }; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
union // 8 bytes alignment
|
|
|
|
|
{ |
|
|
|
|
uint8_t m_Buf[sz]; |
|
|
|
|
uint64_t ll[sz/8]; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
typedef Tag<32> IdentHash; |
|
|
|
|
|
|
|
|
|
#pragma pack(1) |
|
|
|
|
|
|
|
|
@ -53,38 +87,6 @@ namespace data
@@ -53,38 +87,6 @@ namespace data
|
|
|
|
|
|
|
|
|
|
#pragma pack() |
|
|
|
|
|
|
|
|
|
class IdentHash |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
IdentHash (const uint8_t * hash) { memcpy (m_Hash, hash, 32); }; |
|
|
|
|
IdentHash (const IdentHash& ) = default; |
|
|
|
|
#ifndef _WIN32 // FIXME!!! msvs 2013 can't compile it
|
|
|
|
|
IdentHash (IdentHash&& ) = default; |
|
|
|
|
#endif |
|
|
|
|
IdentHash () = default; |
|
|
|
|
|
|
|
|
|
IdentHash& operator= (const IdentHash& ) = default; |
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
IdentHash& operator= (IdentHash&& ) = default; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
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; }; |
|
|
|
|
|
|
|
|
|
bool FromBase32(const std::string&); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
uint8_t m_Hash[32]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Keys CreateRandomKeys (); |
|
|
|
|
void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions
|
|
|
|
|
|
|
|
|
|