CatapultServer  v0.5.0.1 (Elephant)
PrivateKey.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/functions.h"
23 #include "catapult/types.h"
24 
25 namespace catapult { namespace crypto {
26 
27 #ifdef SPAMMER_TOOL
28 #pragma pack(push, 16)
29 #endif
30 
32  class PrivateKey final {
33  public:
35  PrivateKey() = default;
36 
38  ~PrivateKey();
39 
40  public:
42  PrivateKey(PrivateKey&& rhs);
43 
46 
47  public:
49  static PrivateKey FromString(const std::string& str);
50 
52  static PrivateKey FromStringSecure(char* pRawKey, size_t keySize);
53 
55  static PrivateKey Generate(const supplier<uint8_t>& generator);
56 
57  public:
59  inline auto begin() const {
60  return m_key.cbegin();
61  }
62 
64  inline auto end() const {
65  return m_key.cend();
66  }
67 
69  inline auto size() const {
70  return m_key.size();
71  }
72 
74  inline auto data() const {
75  return m_key.data();
76  }
77 
78  public:
80  bool operator==(const PrivateKey& rhs) const;
81 
83  bool operator!=(const PrivateKey& rhs) const;
84 
85  private:
86  static PrivateKey FromString(const char* const pRawKey, size_t keySize);
87 
88  private:
90  };
91 
92 #ifdef SPAMMER_TOOL
93 #pragma pack(pop)
94 #endif
95 }}
catapult::utils::ByteArray::cbegin
constexpr auto cbegin() const noexcept
Returns a const iterator to the first byte.
Definition: ByteArray.h:81
catapult::utils::ByteArray::size
constexpr size_t size() const
Returns the array size.
Definition: ByteArray.h:55
PrivateKey.h
catapult::crypto::PrivateKey::begin
auto begin() const
Returns a const iterator to the beginning of the raw key.
Definition: PrivateKey.h:59
catapult::crypto::PrivateKey::operator==
bool operator==(const PrivateKey &rhs) const
Returns true if this key and rhs are equal.
Definition: PrivateKey.cpp:83
catapult::crypto::PrivateKey::operator=
PrivateKey & operator=(PrivateKey &&rhs)
Move assignment operator.
Definition: PrivateKey.cpp:52
catapult::crypto::PrivateKey
Represents a private key.
Definition: PrivateKey.h:32
functions.h
catapult::crypto::PrivateKey::Generate
static PrivateKey Generate(const supplier< uint8_t > &generator)
Generates a new private key using the specified byte generator.
Definition: PrivateKey.cpp:77
catapult::crypto::PrivateKey::FromString
static PrivateKey FromString(const std::string &str)
Creates a private key from str.
Definition: PrivateKey.cpp:68
catapult::supplier
std::function< T()> supplier
A (stateless) supplier function.
Definition: functions.h:39
catapult::crypto::PrivateKey::m_key
Key m_key
Definition: PrivateKey.h:89
catapult::crypto::PrivateKey::data
auto data() const
Returns a const pointer to the raw key.
Definition: PrivateKey.h:74
catapult::crypto::SecureZero
void SecureZero(Key &key)
Securely zeros out the memory backing the specified key.
Definition: SecureZero.cpp:42
catapult::utils::ByteArray::data
constexpr const uint8_t * data() const noexcept
Returns a const pointer to the underlying array.
Definition: ByteArray.h:70
catapult::crypto::PrivateKey::PrivateKey
PrivateKey()=default
Creates a private key.
catapult::utils::ByteArray::begin
constexpr auto begin() const noexcept
Returns a const iterator to the first byte.
Definition: ByteArray.h:91
size
uint64_t size
Definition: MemoryCounters.cpp:65
catapult::crypto::PrivateKey::end
auto end() const
Returns a const iterator to the end of the raw key.
Definition: PrivateKey.h:64
catapult::crypto::PrivateKey::size
auto size() const
Returns the size of the key.
Definition: PrivateKey.h:69
SecureZero.h
types.h
catapult::utils::ParseHexStringIntoContainer
void ParseHexStringIntoContainer(const char *const pHexData, size_t dataSize, TContainer &outputContainer)
Parses a hex string (pHexData with size dataSize) into outputContainer.
Definition: HexParser.h:49
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::ByteArray< Key_Size, Key_tag >
HexParser.h
m_dataSize
size_t m_dataSize
Definition: PrivateKey.cpp:43
catapult::utils::ByteArray::cend
constexpr auto cend() const noexcept
Returns a const iterator to one past the last byte.
Definition: ByteArray.h:86
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
m_pData
uint8_t * m_pData
Definition: PrivateKey.cpp:42
catapult::crypto::PrivateKey::~PrivateKey
~PrivateKey()
Destroys the private key.
Definition: PrivateKey.cpp:58
catapult::crypto::PrivateKey::operator!=
bool operator!=(const PrivateKey &rhs) const
Returns true if this key and rhs are not equal.
Definition: PrivateKey.cpp:87
catapult::crypto::PrivateKey::FromStringSecure
static PrivateKey FromStringSecure(char *pRawKey, size_t keySize)
Creates a private key from pRawKey with size keySize and securely erases pRawKey.
Definition: PrivateKey.cpp:72