forked from PurpleI2P/i2pd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters