StormByte C++ Library: Crypto module 1.0.0
StormByte-Crypto is a StormByte library module for handling cryptographic operations
All Classes Namespaces Functions Pages
Public Member Functions | List of all members
StormByte::Crypto::Symmetric Class Referencefinal

A class for managing symmetric encryption and decryption. More...

#include <symmetric.hxx>

Inheritance diagram for StormByte::Crypto::Symmetric:
Inheritance graph
[legend]
Collaboration diagram for StormByte::Crypto::Symmetric:
Collaboration graph
[legend]

Public Member Functions

 Symmetric (const Algorithm::Symmetric &algorithm, const size_t &password_size=16) noexcept
 Constructs a Symmetric instance with a randomly generated password.
 
 Symmetric (const Algorithm::Symmetric &algorithm, const std::string &password) noexcept
 Constructs a Symmetric instance with a user-provided password.
 
 Symmetric (const Symmetric &crypter)=default
 Copy constructor for the Symmetric class.
 
 Symmetric (Symmetric &&crypter) noexcept=default
 Move constructor for the Symmetric class.
 
 ~Symmetric () noexcept override=default
 Destructor for the Symmetric class.
 
Symmetricoperator= (const Symmetric &crypter)=default
 Copy assignment operator for the Symmetric class.
 
Symmetricoperator= (Symmetric &&crypter) noexcept=default
 Move assignment operator for the Symmetric class.
 
Expected< std::string, ExceptionEncrypt (const std::string &input) const noexcept override
 Encrypts a string input.
 
Expected< Buffer::Simple, ExceptionEncrypt (const Buffer::Simple &buffer) const noexcept override
 Encrypts a buffer.
 
Buffer::Consumer Encrypt (const Buffer::Consumer consumer) const noexcept override
 Encrypts data asynchronously using a Consumer/Producer model.
 
Expected< std::string, ExceptionDecrypt (const std::string &input) const noexcept override
 Decrypts a string input.
 
Expected< Buffer::Simple, ExceptionDecrypt (const Buffer::Simple &buffer) const noexcept override
 Decrypts a buffer.
 
Buffer::Consumer Decrypt (const Buffer::Consumer consumer) const noexcept override
 Decrypts data asynchronously using a Consumer/Producer model.
 
const std::string & Password () const noexcept
 Returns the password used for encryption and decryption.
 
void Password (const std::string &password) noexcept
 Sets the password for encryption and decryption.
 
void Password (std::string &&password) noexcept
 Sets the password for encryption and decryption (move version).
 
- Public Member Functions inherited from StormByte::Crypto::Crypter
 Crypter () noexcept=default
 Default constructor for the Crypter class.
 
 Crypter (const Crypter &crypter)=default
 Copy constructor for the Crypter class.
 
 Crypter (Crypter &&crypter) noexcept=default
 Move constructor for the Crypter class.
 
virtual ~Crypter () noexcept=default
 Virtual destructor for the Crypter class.
 
Crypteroperator= (const Crypter &crypter)=default
 Copy assignment operator for the Crypter class.
 
Crypteroperator= (Crypter &&crypter) noexcept=default
 Move assignment operator for the Crypter class.
 

Detailed Description

A class for managing symmetric encryption and decryption.

This class provides methods for encrypting and decrypting data using symmetric encryption algorithms.

Constructor & Destructor Documentation

◆ Symmetric() [1/4]

StormByte::Crypto::Symmetric::Symmetric ( const Algorithm::Symmetric &  algorithm,
const size_t &  password_size = 16 
)
noexcept

Constructs a Symmetric instance with a randomly generated password.

This constructor initializes the Symmetric instance with the specified symmetric encryption algorithm and a randomly generated password of the specified size.

Parameters
algorithmThe symmetric encryption algorithm to use.
password_sizeThe size of the randomly generated password (default is 16 bytes).

◆ Symmetric() [2/4]

StormByte::Crypto::Symmetric::Symmetric ( const Algorithm::Symmetric &  algorithm,
const std::string &  password 
)
explicitnoexcept

Constructs a Symmetric instance with a user-provided password.

This constructor initializes the Symmetric instance with the specified symmetric encryption algorithm and a user-provided password.

Parameters
algorithmThe symmetric encryption algorithm to use.
passwordThe password to use for encryption and decryption.

◆ Symmetric() [3/4]

StormByte::Crypto::Symmetric::Symmetric ( const Symmetric crypter)
default

Copy constructor for the Symmetric class.

Creates a copy of the given Symmetric instance.

Parameters
crypterThe Symmetric instance to copy.

◆ Symmetric() [4/4]

StormByte::Crypto::Symmetric::Symmetric ( Symmetric &&  crypter)
defaultnoexcept

Move constructor for the Symmetric class.

Moves the given Symmetric instance into the current instance.

Parameters
crypterThe Symmetric instance to move.

◆ ~Symmetric()

StormByte::Crypto::Symmetric::~Symmetric ( )
overridedefaultnoexcept

Destructor for the Symmetric class.

Cleans up the Symmetric instance.

Member Function Documentation

◆ Decrypt() [1/3]

Buffer::Consumer StormByte::Crypto::Symmetric::Decrypt ( const Buffer::Consumer  consumer) const
overridevirtualnoexcept

Decrypts data asynchronously using a Consumer/Producer model.

This method decrypts the data provided by the Consumer buffer using the symmetric encryption algorithm.

Parameters
consumerThe Consumer buffer containing the encrypted data.
Returns
A Consumer buffer containing the decrypted data.

Implements StormByte::Crypto::Crypter.

◆ Decrypt() [2/3]

Expected< Buffer::Simple, Exception > StormByte::Crypto::Symmetric::Decrypt ( const Buffer::Simple &  buffer) const
overridevirtualnoexcept

Decrypts a buffer.

This method decrypts the given buffer using the symmetric encryption algorithm.

Parameters
bufferThe buffer to decrypt.
Returns
An Expected containing the decrypted buffer or an error.

Implements StormByte::Crypto::Crypter.

◆ Decrypt() [3/3]

Expected< std::string, Exception > StormByte::Crypto::Symmetric::Decrypt ( const std::string &  input) const
overridevirtualnoexcept

Decrypts a string input.

This method decrypts the given string input using the symmetric encryption algorithm.

Parameters
inputThe string to decrypt.
Returns
An Expected containing the decrypted string or an error.

Implements StormByte::Crypto::Crypter.

◆ Encrypt() [1/3]

Buffer::Consumer StormByte::Crypto::Symmetric::Encrypt ( const Buffer::Consumer  consumer) const
overridevirtualnoexcept

Encrypts data asynchronously using a Consumer/Producer model.

This method encrypts the data provided by the Consumer buffer using the symmetric encryption algorithm.

Parameters
consumerThe Consumer buffer containing the input data.
Returns
A Consumer buffer containing the encrypted data.

Implements StormByte::Crypto::Crypter.

◆ Encrypt() [2/3]

Expected< Buffer::Simple, Exception > StormByte::Crypto::Symmetric::Encrypt ( const Buffer::Simple &  buffer) const
overridevirtualnoexcept

Encrypts a buffer.

This method encrypts the given buffer using the symmetric encryption algorithm.

Parameters
bufferThe buffer to encrypt.
Returns
An Expected containing the encrypted buffer or an error.

Implements StormByte::Crypto::Crypter.

◆ Encrypt() [3/3]

Expected< std::string, Exception > StormByte::Crypto::Symmetric::Encrypt ( const std::string &  input) const
overridevirtualnoexcept

Encrypts a string input.

This method encrypts the given string input using the symmetric encryption algorithm.

Parameters
inputThe string to encrypt.
Returns
An Expected containing the encrypted string or an error.

Implements StormByte::Crypto::Crypter.

◆ operator=() [1/2]

Symmetric & StormByte::Crypto::Symmetric::operator= ( const Symmetric crypter)
default

Copy assignment operator for the Symmetric class.

Assigns the values from the given Symmetric instance to the current instance.

Parameters
crypterThe Symmetric instance to copy.
Returns
A reference to the updated Symmetric instance.

◆ operator=() [2/2]

Symmetric & StormByte::Crypto::Symmetric::operator= ( Symmetric &&  crypter)
defaultnoexcept

Move assignment operator for the Symmetric class.

Moves the values from the given Symmetric instance to the current instance.

Parameters
crypterThe Symmetric instance to move.
Returns
A reference to the updated Symmetric instance.

◆ Password() [1/3]

const std::string & StormByte::Crypto::Symmetric::Password ( ) const
noexcept

Returns the password used for encryption and decryption.

This method returns the password used by the Symmetric instance for encryption and decryption.

Returns
The password as a string.

◆ Password() [2/3]

void StormByte::Crypto::Symmetric::Password ( const std::string &  password)
noexcept

Sets the password for encryption and decryption.

This method sets a new password for the Symmetric instance to use for encryption and decryption.

Parameters
passwordThe new password to use.

◆ Password() [3/3]

void StormByte::Crypto::Symmetric::Password ( std::string &&  password)
noexcept

Sets the password for encryption and decryption (move version).

This method sets a new password for the Symmetric instance to use for encryption and decryption. The password is moved into the instance to avoid unnecessary copying.

Parameters
passwordThe new password to use (rvalue reference).

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