StormByte-Crypto 2.0.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 std::optional< Secure::Password > & PrivateKey () const noexcept
 Private key, if any.
 
Construction
 Generic (const Generic &other)=default
 Copy constructor.
 
 Generic (Generic &&other) noexcept=default
 Move constructor.
 
virtual ~Generic () noexcept
 Destructor.
 
Generic & operator= (const Generic &other)=default
 Copy assignment.
 
Generic & operator= (Generic &&other) noexcept=default
 Move assignment.
 
Persistence
bool Save (const std::filesystem::path &directory, std::string_view baseName, StorageFormat format=StorageFormat::PEM) const noexcept
 Write public and private files under a directory.
 
bool Save (const std::filesystem::path &directory, std::string_view baseName, const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Write public and private files.
 
bool SavePublic (const std::filesystem::path &filePath, StorageFormat format=StorageFormat::PEM) const noexcept
 Write only the public key.
 
bool SavePrivate (const std::filesystem::path &filePath, StorageFormat format=StorageFormat::PEM) const noexcept
 Write only the private key, unencrypted.
 
bool SavePrivate (const std::filesystem::path &filePath, const Secure::Password &encryptPassword, StorageFormat format=StorageFormat::PEM) const noexcept
 Write only the private key, encrypted (prefer PEM).
 
- Public Member Functions inherited from StormByte::Safe::Clonable< Generic >
constexpr Clonable ()=default
 
constexpr Clonable (const Clonable &)=default
 
constexpr Clonable (Clonable &&) noexcept=default
 
constexpr Clonable & operator= (const Clonable &)=default
 
constexpr Clonable & operator= (Clonable &&) noexcept=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, std::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.
 
std::optional< Secure::Password > m_private_key
 Private material, if any.
 

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.

Constructor & Destructor Documentation

◆ Generic() [1/3]

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

Copy constructor.

Parameters
otherKeypair to copy.

◆ Generic() [2/3]

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

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,
std::optional< Secure::Password >  private_key = std::nullopt 
)
inlineprotected

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]

Copy assignment.

Parameters
otherKeypair to copy.
Returns
Reference to this keypair.

◆ operator=() [2/2]

Move assignment.

Parameters
otherKeypair to move.
Returns
Reference to this keypair.

◆ PrivateKey()

const std::optional< Secure::Password > & StormByte::Crypto::KeyPair::Generic::PrivateKey ( ) const
inlinenoexcept

Private key, if any.

Returns
Shared Password, or empty.

◆ PublicKey()

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

Public key string.

Returns
Public material owned by this keypair.

◆ Save() [1/2]

bool StormByte::Crypto::KeyPair::Generic::Save ( const std::filesystem::path &  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() [2/2]

bool StormByte::Crypto::KeyPair::Generic::Save ( const std::filesystem::path &  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/2]

bool StormByte::Crypto::KeyPair::Generic::SavePrivate ( const std::filesystem::path &  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() [2/2]

bool StormByte::Crypto::KeyPair::Generic::SavePrivate ( const std::filesystem::path &  filePath,
StorageFormat  format = StorageFormat::PEM 
) const
noexcept

Write only the private key, unencrypted.

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

◆ SavePublic()

bool StormByte::Crypto::KeyPair::Generic::SavePublic ( const std::filesystem::path &  filePath,
StorageFormat  format = StorageFormat::PEM 
) const
noexcept

Write only the public key.

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

◆ Type()

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

Algorithm of this keypair.

Returns
Keypair type.

Member Data Documentation

◆ m_private_key

std::optional<Secure::Password> StormByte::Crypto::KeyPair::Generic::m_private_key
protected

Private material, if any.

◆ 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: