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/clonable.hxx>
4#include <StormByte/crypto/typedefs.hxx>
5#include <StormByte/crypto/visibility.h>
6
7#include <filesystem>
8#include <optional>
9#include <string>
10
15namespace StormByte::Crypto::KeyPair {
20 enum class Type {
21 DSA,
22 ECC,
23 ECDH,
24 ECDSA,
25 ED25519,
26 RSA,
27 X25519,
28 };
29
34 class STORMBYTE_CRYPTO_PUBLIC Generic: public StormByte::Clonable<Generic> {
35 public:
40 Generic(const Generic& other) = default;
41
46 Generic(Generic&& other) noexcept = default;
47
51 virtual ~Generic() noexcept = default;
52
58 Generic& operator=(const Generic& other) = default;
59
65 Generic& operator=(Generic&& other) noexcept = default;
66
71 inline const std::string& PublicKey() const noexcept {
72 return m_public_key;
73 }
74
79 inline const std::optional<std::string>& PrivateKey() const noexcept {
80 return m_private_key;
81 }
82
87 inline enum Type Type() const noexcept {
88 return m_type;
89 }
90
97 bool Save(const std::filesystem::path& path, const std::string& name) const noexcept;
98
99 protected:
100 enum Type m_type;
101 std::string m_public_key;
102 std::optional<std::string> m_private_key;
103
108 inline Generic(enum Type type, const std::string& public_key, std::optional<std::string> private_key = std::nullopt):
109 m_type(type), m_public_key(public_key), m_private_key(private_key) {}
110
111 private:
112
113 };
114
121 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Generate(Type type, unsigned short bits) noexcept;
122
123 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Load(const std::filesystem::path& publicKeyPath, const std::filesystem::path& privateKeyPath) noexcept;
124}
A generic class.
Definition generic.hxx:34
std::string m_public_key
The public key.
Definition generic.hxx:101
enum Type m_type
The type of keypair.
Definition generic.hxx:100
bool Save(const std::filesystem::path &path, const std::string &name) const noexcept
Saves the keypair to the specified file paths.
virtual ~Generic() noexcept=default
Virtual destructor.
Generic(Generic &&other) noexcept=default
Move constructor.
const std::optional< std::string > & PrivateKey() const noexcept
Gets the private key of the keypair.
Definition generic.hxx:79
Generic(enum Type type, const std::string &public_key, std::optional< std::string > private_key=std::nullopt)
Constructor.
Definition generic.hxx:108
std::optional< std::string > m_private_key
The private key.
Definition generic.hxx:102
Generic(const Generic &other)=default
Copy constructor.
enum Type Type() const noexcept
Gets the type of keypair.
Definition generic.hxx:87