StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Crypto::KeyPair::Generic Class Reference

Abstract keypair. More...

#include <StormByte/crypto/keypair/generic.hxx>

Inheritance diagram for StormByte::Crypto::KeyPair::Generic:
Collaboration diagram for StormByte::Crypto::KeyPair::Generic:

Public Member Functions

enum Type Type () const noexcept
 Algorithm of this keypair.
const StormByte::Safe::String & PublicKey () const noexcept
 Public key string.
bool HasPrivateKey () const noexcept
 Whether a private key is stored.
const StormByte::Safe::Optional< Secure::Password > & PrivateKey () const noexcept
 Private key, if any.
Construction
 Generic (const Generic &other)
 Copy constructor.
 Generic (Generic &&other) noexcept
 Move constructor.
virtual ~Generic () noexcept
 Destructor.
Generic & operator= (const Generic &other)
 Copy assignment.
Generic & operator= (Generic &&other) noexcept
 Move assignment.
Persistence

File overloads write exactly the bytes the in-memory overloads return.

StormByte::Safe::SecureBinary SavePublic (StorageFormat format=StorageFormat::PEM) const noexcept
 Encode the public key in memory.
StormByte::Safe::SecureBinary SavePrivate (StorageFormat format=StorageFormat::PEM) const noexcept
 Encode the private key in memory, unencrypted.
StormByte::Safe::SecureBinary SavePrivate (const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Encode the private key in memory as encrypted PKCS#8 (prefer PEM).
bool Save (PathView directory, std::string_view baseName, StorageFormat format=StorageFormat::PEM) const noexcept
 Write public and private files under a directory.
template<typename Compatibility = void>
bool Save (const std::filesystem::path &directory, std::string_view baseName, StorageFormat format=StorageFormat::PEM) const noexcept
 Caller-side filesystem path adapter for unencrypted Save.
bool Save (PathView directory, std::string_view baseName, const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Write public and private files.
template<typename Compatibility = void>
bool Save (const std::filesystem::path &directory, std::string_view baseName, const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Caller-side filesystem path adapter for encrypted Save.
bool SavePublic (PathView filePath, StorageFormat format=StorageFormat::PEM) const noexcept
 Write only the public key.
template<typename Compatibility = void>
bool SavePublic (const std::filesystem::path &filePath, StorageFormat format=StorageFormat::PEM) const noexcept
 Caller-side filesystem path adapter for SavePublic.
bool SavePrivate (PathView filePath, StorageFormat format=StorageFormat::PEM) const noexcept
 Write only the private key, unencrypted.
template<typename Compatibility = void>
bool SavePrivate (const std::filesystem::path &filePath, StorageFormat format=StorageFormat::PEM) const noexcept
 Caller-side filesystem path adapter for unencrypted SavePrivate.
bool SavePrivate (PathView filePath, const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Write only the private key, encrypted (prefer PEM).
template<typename Compatibility = void>
bool SavePrivate (const std::filesystem::path &filePath, const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Caller-side filesystem path adapter for encrypted SavePrivate.
Public Member Functions inherited from StormByte::Safe::Clonable< Generic >
constexpr Clonable ()=default
constexpr Clonable & operator= (const Clonable &)=default
virtual constexpr ~Clonable () noexcept=default
virtual PointerType Clone () const =0
virtual PointerType Move ()=0

Protected Member Functions

 Generic (enum Type type, StormByte::Safe::String public_key, StormByte::Safe::Optional< Secure::Password > private_key=std::nullopt)
 Construct with algorithm and material.

Protected Attributes

enum Type m_type
 Algorithm.
StormByte::Safe::String m_public_key
 Public material.
StormByte::Safe::Optional< Secure::Password > m_private_key
 Crypto-owned optional private material.

Additional Inherited Members

Public Types inherited from StormByte::Safe::Clonable< Generic >
typedef SmartPointer PointerType
Static Public Member Functions inherited from StormByte::Safe::Clonable< Generic >
static PointerType MakePointer (Args &&... args)

Detailed Description

Abstract keypair.

Concrete algorithms derive from this.

Public key is a non-secret StormByte::Safe::String (typically Base64 SPKI DER). Private key, when present, is a StormByte::Crypto::Secure::Password holding PKCS#8 or native DER and is wiped with the last owner.

Note
Conditional DLL safety requires ABI-compatible modules and Crypto, Base and Buffer to remain loaded while values or ownership callbacks exist. Crypto binds private-material callbacks and defines value operations out of line. Derived providers must preserve these requirements and use boundary-safe fields, allocation, destruction and Clone/Move paths.

Constructor & Destructor Documentation

◆ Generic() [1/3]

StormByte::Crypto::KeyPair::Generic::Generic ( const Generic & other)

Copy constructor.

Parameters
otherKeypair to copy.

◆ Generic() [2/3]

StormByte::Crypto::KeyPair::Generic::Generic ( Generic && other)
noexcept

Move constructor.

Parameters
otherKeypair to move.

◆ ~Generic()

virtual StormByte::Crypto::KeyPair::Generic::~Generic ( )
virtualnoexcept

Destructor.

Drops the private-key handle.

◆ Generic() [3/3]

StormByte::Crypto::KeyPair::Generic::Generic ( enum Type type,
StormByte::Safe::String public_key,
StormByte::Safe::Optional< Secure::Password > private_key = std::nullopt )
protected

Construct with algorithm and material.

Parameters
typeAlgorithm.
public_keyPublic material.
private_keyOptional private Password.

Member Function Documentation

◆ HasPrivateKey()

bool StormByte::Crypto::KeyPair::Generic::HasPrivateKey ( ) const
inlinenoexcept

Whether a private key is stored.

Returns
true if present.

◆ operator=() [1/2]

Generic & StormByte::Crypto::KeyPair::Generic::operator= ( const Generic & other)

Copy assignment.

Parameters
otherKeypair to copy.
Returns
Reference to this keypair.

◆ operator=() [2/2]

Generic & StormByte::Crypto::KeyPair::Generic::operator= ( Generic && other)
noexcept

Move assignment.

Parameters
otherKeypair to move.
Returns
Reference to this keypair.

◆ PrivateKey()

const StormByte::Safe::Optional< Secure::Password > & StormByte::Crypto::KeyPair::Generic::PrivateKey ( ) const
inlinenoexcept

Private key, if any.

Returns
Safe optional containing a shared Password, or empty.
Note
Dereference returns a Password snapshot. Retain that snapshot for the lifetime of any borrowed byte pointer or span.

◆ PublicKey()

const StormByte::Safe::String & StormByte::Crypto::KeyPair::Generic::PublicKey ( ) const
inlinenoexcept

Public key string.

Returns
Public material owned by this keypair.

◆ Save() [1/4]

template<typename Compatibility = void>
bool StormByte::Crypto::KeyPair::Generic::Save ( const std::filesystem::path & directory,
std::string_view baseName,
const Secure::Password & encryptPassword,
StorageFormat format = StorageFormat::PEM ) const
inlinenoexcept

Caller-side filesystem path adapter for encrypted Save.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
directoryExisting directory.
baseNameFile stem.
encryptPasswordPassword for the private file.
formatPrefer PEM when encrypting.
Returns
true on success.

◆ Save() [2/4]

template<typename Compatibility = void>
bool StormByte::Crypto::KeyPair::Generic::Save ( const std::filesystem::path & directory,
std::string_view baseName,
StorageFormat format = StorageFormat::PEM ) const
inlinenoexcept

Caller-side filesystem path adapter for unencrypted Save.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
directoryExisting directory.
baseNameFile stem.
formatPEM or DER.
Returns
true on success.

◆ Save() [3/4]

bool StormByte::Crypto::KeyPair::Generic::Save ( PathView directory,
std::string_view baseName,
const Secure::Password & encryptPassword,
StorageFormat format = StorageFormat::PEM ) const
noexcept

Write public and private files.

Private key encrypted (prefer PEM).

Parameters
directoryExisting directory.
baseNameFile stem.
encryptPasswordPassword for the private file.
formatPrefer PEM when encrypting.
Returns
true on success.

◆ Save() [4/4]

bool StormByte::Crypto::KeyPair::Generic::Save ( PathView directory,
std::string_view baseName,
StorageFormat format = StorageFormat::PEM ) const
noexcept

Write public and private files under a directory.

Private key unencrypted.

Parameters
directoryExisting directory.
baseNameFile stem.
formatPEM or DER.
Returns
true on success.

◆ SavePrivate() [1/6]

StormByte::Safe::SecureBinary StormByte::Crypto::KeyPair::Generic::SavePrivate ( const Secure::Password & encryptPassword,
StorageFormat format = StorageFormat::PEM ) const
noexcept

Encode the private key in memory as encrypted PKCS#8 (prefer PEM).

Parameters
encryptPasswordEncryption password.
formatPrefer PEM.
Returns
Encoded key wiped on release, empty without a private key or on failure.

◆ SavePrivate() [2/6]

template<typename Compatibility = void>
bool StormByte::Crypto::KeyPair::Generic::SavePrivate ( const std::filesystem::path & filePath,
const Secure::Password & encryptPassword,
StorageFormat format = StorageFormat::PEM ) const
inlinenoexcept

Caller-side filesystem path adapter for encrypted SavePrivate.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
filePathDestination.
encryptPasswordPassword.
formatPrefer PEM.
Returns
true on success.

◆ SavePrivate() [3/6]

template<typename Compatibility = void>
bool StormByte::Crypto::KeyPair::Generic::SavePrivate ( const std::filesystem::path & filePath,
StorageFormat format = StorageFormat::PEM ) const
inlinenoexcept

Caller-side filesystem path adapter for unencrypted SavePrivate.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
filePathDestination.
formatPEM or DER.
Returns
true on success.

◆ SavePrivate() [4/6]

bool StormByte::Crypto::KeyPair::Generic::SavePrivate ( PathView filePath,
const Secure::Password & encryptPassword,
StorageFormat format = StorageFormat::PEM ) const
noexcept

Write only the private key, encrypted (prefer PEM).

Parameters
filePathDestination.
encryptPasswordPassword.
formatPrefer PEM.
Returns
true on success.

◆ SavePrivate() [5/6]

bool StormByte::Crypto::KeyPair::Generic::SavePrivate ( PathView filePath,
StorageFormat format = StorageFormat::PEM ) const
noexcept

Write only the private key, unencrypted.

Parameters
filePathDestination.
formatPEM or DER.
Returns
true on success.

◆ SavePrivate() [6/6]

StormByte::Safe::SecureBinary StormByte::Crypto::KeyPair::Generic::SavePrivate ( StorageFormat format = StorageFormat::PEM) const
noexcept

Encode the private key in memory, unencrypted.

Parameters
formatPEM or DER.
Returns
Encoded key wiped on release, empty without a private key or on failure.

◆ SavePublic() [1/3]

template<typename Compatibility = void>
bool StormByte::Crypto::KeyPair::Generic::SavePublic ( const std::filesystem::path & filePath,
StorageFormat format = StorageFormat::PEM ) const
inlinenoexcept

Caller-side filesystem path adapter for SavePublic.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
filePathDestination.
formatPEM or DER.
Returns
true on success.

◆ SavePublic() [2/3]

bool StormByte::Crypto::KeyPair::Generic::SavePublic ( PathView filePath,
StorageFormat format = StorageFormat::PEM ) const
noexcept

Write only the public key.

Parameters
filePathDestination.
formatPEM or DER.
Returns
true on success.

◆ SavePublic() [3/3]

StormByte::Safe::SecureBinary StormByte::Crypto::KeyPair::Generic::SavePublic ( StorageFormat format = StorageFormat::PEM) const
noexcept

Encode the public key in memory.

Parameters
formatPEM or DER.
Returns
Encoded key, empty on failure.

◆ Type()

enum Type StormByte::Crypto::KeyPair::Generic::Type ( ) const
inlinenoexcept

Algorithm of this keypair.

Returns
Keypair type.

Member Data Documentation

◆ m_private_key

StormByte::Safe::Optional<Secure::Password> StormByte::Crypto::KeyPair::Generic::m_private_key
protected

Crypto-owned optional private material.

◆ m_public_key

StormByte::Safe::String StormByte::Crypto::KeyPair::Generic::m_public_key
protected

Public material.

◆ m_type

enum Type StormByte::Crypto::KeyPair::Generic::m_type
protected

Algorithm.


The documentation for this class was generated from the following file: