StormByte C++ Library: Crypto module 1.0.0
StormByte-Crypto is a StormByte library module for handling cryptographic operations
Loading...
Searching...
No Matches
keypair.hxx
1#pragma once
2
3#include <StormByte/crypto/algorithm.hxx>
4#include <StormByte/crypto/exception.hxx>
5#include <StormByte/expected.hxx>
6
7#include <optional>
8#include <string>
9
14namespace StormByte::Crypto {
23 class STORMBYTE_CRYPTO_PUBLIC KeyPair final {
24 public:
34 KeyPair(const std::string& pub, const std::string& priv) noexcept;
35
44 KeyPair(const std::string& pub) noexcept;
45
54 KeyPair(std::string&& pub, std::string&& priv) noexcept;
55
64 KeyPair(std::string&& pub) noexcept;
65
73 KeyPair(const KeyPair& other) = default;
74
82 KeyPair(KeyPair&& other) noexcept = default;
83
90 ~KeyPair() noexcept = default;
91
100 KeyPair& operator=(const KeyPair& other) = default;
101
110 KeyPair& operator=(KeyPair&& other) noexcept = default;
111
119 const std::string& PublicKey() const noexcept;
120
129 const std::optional<std::string>& PrivateKey() const noexcept;
130
140 [[nodiscard]]
141 static Expected<KeyPair, Exception> Generate(const Algorithm::Asymmetric& algo, const size_t& key_size) noexcept;
142
152 [[nodiscard]]
153 static Expected<KeyPair, Exception> Generate(const Algorithm::Asymmetric& algo, const std::string& curve_name) noexcept;
154
164 [[nodiscard]]
165 static Expected<KeyPair, Exception> Generate(const Algorithm::Sign& algo, const size_t& key_size) noexcept;
166
176 [[nodiscard]]
177 static Expected<KeyPair, Exception> Generate(const Algorithm::Sign& algo, const std::string& curve_name) noexcept;
178
188 [[nodiscard]]
189 static Expected<KeyPair, Exception> Generate(const Algorithm::SecretShare& algo, const std::string& curve_name) noexcept;
190
191 private:
192 std::string m_public_key;
193 std::optional<std::string> m_private_key;
194 };
195}
A class for managing asymmetric encryption and decryption.
Definition asymetric.hxx:17
A class representing an exception in the crypto module.
Definition exception.hxx:15
A class representing a public/private key pair.
Definition keypair.hxx:23
KeyPair(std::string &&pub) noexcept
Constructs a KeyPair with a public key only (move version).
KeyPair(const std::string &pub, const std::string &priv) noexcept
Constructs a KeyPair with a public and private key.
KeyPair(const std::string &pub) noexcept
Constructs a KeyPair with a public key only.
KeyPair(KeyPair &&other) noexcept=default
Move constructor.
KeyPair(const KeyPair &other)=default
Copy constructor.
~KeyPair() noexcept=default
Destructor.
KeyPair(std::string &&pub, std::string &&priv) noexcept
Constructs a KeyPair with a public and private key (move version).
The namespace containing cryptographic algorithms.