StormByte C++ Library: Crypto module 0.0.9999
StormByte-Crypto is a StormByte library module for handling cryptographic operations
Loading...
Searching...
No Matches
generic.hxx
1#pragma once
2
3#include <StormByte/buffer/consumer.hxx>
4#include <StormByte/clonable.hxx>
5#include <StormByte/crypto/keypair/generic.hxx>
6
11namespace StormByte::Crypto::Signer {
16 enum class Type {
17 DSA,
18 ECDSA,
19 ED25519,
20 RSA,
21 };
22
27 class STORMBYTE_CRYPTO_PUBLIC Generic: public StormByte::Clonable<Generic> {
28 public:
33 Generic(const Generic& other) = default;
34
39 Generic(Generic&& other) noexcept = default;
40
44 virtual ~Generic() noexcept = default;
45
51 Generic& operator=(const Generic& other) = default;
52
58 Generic& operator=(Generic&& other) noexcept = default;
59
64 KeyPair::Generic::PointerType KeyPair() const noexcept {
65 return m_keypair;
66 }
67
74 inline bool Sign(std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept {
75 return DoSign(input, output);
76 }
77
84 inline bool Sign(const Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
85 return DoSign(const_cast<Buffer::ReadOnly&>(input), output, ReadMode::Copy);
86 }
87
94 inline bool Sign(Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
95 return DoSign(input, output, ReadMode::Move);
96 }
97
104 inline Buffer::Consumer Sign(Buffer::Consumer consumer, ReadMode mode = ReadMode::Move) const noexcept {
105 return DoSign(consumer, mode);
106 }
107
114 inline bool Verify(std::span<const std::byte> input, const std::string& signature) const noexcept {
115 return DoVerify(input, signature);
116 }
117
124 inline bool Verify(const Buffer::ReadOnly& input, const std::string& signature) const noexcept {
125 return DoVerify(const_cast<Buffer::ReadOnly&>(input), signature, ReadMode::Copy);
126 }
127
134 inline bool Verify(Buffer::ReadOnly& input, const std::string& signature) const noexcept {
135 return DoVerify(input, signature, ReadMode::Move);
136 }
137
145 inline bool Verify(Buffer::Consumer consumer, const std::string& signature, ReadMode mode = ReadMode::Move) const noexcept {
146 return DoVerify(consumer, signature, mode);
147 }
148
149 protected:
150 enum Type m_type;
151 KeyPair::Generic::PointerType m_keypair;
152
158 inline Generic(enum Type type, KeyPair::Generic::PointerType keypair):
159 m_type(type), m_keypair(keypair) {}
160
166 inline Generic(enum Type type, const KeyPair::Generic& keypair):
167 m_type(type), m_keypair(keypair.Clone()) {}
168
174 inline Generic(enum Type type, KeyPair::Generic&& keypair):
175 m_type(type), m_keypair(keypair.Move()) {}
176
177 private:
185 bool DoSign(Buffer::ReadOnly& input, Buffer::WriteOnly& output, ReadMode mode) const noexcept;
186
194 virtual bool DoSign(std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept = 0;
195
202 virtual Buffer::Consumer DoSign(Buffer::Consumer consumer, ReadMode mode) const noexcept = 0;
203
211 bool DoVerify(Buffer::ReadOnly& input, const std::string& signature, ReadMode mode) const noexcept;
212
219 virtual bool DoVerify(std::span<const std::byte> input, const std::string& signature) const noexcept = 0;
220
228 virtual bool DoVerify(Buffer::Consumer consumer, const std::string& signature, ReadMode mode) const noexcept = 0;
229 };
230
237 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Create(enum Type type, KeyPair::Generic::PointerType keypair) noexcept;
238
245 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Create(enum Type type, const KeyPair::Generic& keypair) noexcept;
252 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Create(enum Type type, KeyPair::Generic&& keypair) noexcept;
253}
A generic class.
Definition generic.hxx:34
A generic signer class.
Definition generic.hxx:27
Generic(enum Type type, KeyPair::Generic &&keypair)
Constructor.
Definition generic.hxx:174
bool Verify(std::span< const std::byte > input, const std::string &signature) const noexcept
Verify data from input span to output buffer.
Definition generic.hxx:114
enum Type m_type
The type of signer.
Definition generic.hxx:150
Generic(const Generic &other)=default
Copy constructor.
KeyPair::Generic::PointerType m_keypair
The password used for asymmetric encryption.
Definition generic.hxx:151
bool Verify(Buffer::ReadOnly &input, const std::string &signature) const noexcept
Verify data from input buffer to output buffer, moving the input data.
Definition generic.hxx:134
bool Verify(Buffer::Consumer consumer, const std::string &signature, ReadMode mode=ReadMode::Move) const noexcept
Verify data from a Consumer buffer.
Definition generic.hxx:145
bool Verify(const Buffer::ReadOnly &input, const std::string &signature) const noexcept
Verify data from input buffer to output buffer.
Definition generic.hxx:124
Generic(enum Type type, KeyPair::Generic::PointerType keypair)
Constructor.
Definition generic.hxx:158
virtual ~Generic() noexcept=default
Virtual destructor.
Buffer::Consumer Sign(Buffer::Consumer consumer, ReadMode mode=ReadMode::Move) const noexcept
Sign data from a Consumer buffer.
Definition generic.hxx:104
bool Sign(const Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Sign data from input buffer to output buffer.
Definition generic.hxx:84
Generic(Generic &&other) noexcept=default
Move constructor.
bool Sign(std::span< const std::byte > input, Buffer::WriteOnly &output) const noexcept
Sign data from input span to output buffer.
Definition generic.hxx:74
Generic(enum Type type, const KeyPair::Generic &keypair)
Constructor.
Definition generic.hxx:166
bool Sign(Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Sign data from input buffer to output buffer, moving the input data.
Definition generic.hxx:94
The namespace containing all the keypair-related classes.