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

Shared, wiped container for passwords and raw key material. More...

#include <StormByte/crypto/secure/password.hxx>

Public Member Functions

StormByte::ByteSize Size () const noexcept
 Stored size in bytes.
bool Empty () const noexcept
 Whether Size() is 0.
 operator bool () const noexcept
 true if the password is not empty.
bool operator== (const Password &other) const noexcept
 Constant-time equality.
bool operator!= (const Password &other) const noexcept
 Inequality.
Construction
 Password () noexcept
 Empty password, suitable for Safe collections.
 Password (std::string_view value)
 Copy borrowed text into secure storage without wiping its source.
 Password (StormByte::Safe::String &value)
 From DLL-safe text.
 Password (const char *value)
 From a C string up to the terminator.
 Password (const void *data, StormByte::ByteSize size)
 From raw bytes.
 Password (const Password &other)
 Copy constructor.
 Password (Password &&other) noexcept
 Move constructor.
 ~Password ()
 Destructor.
Password & operator= (const Password &other)
 Copy assignment.
Password & operator= (Password &&other) noexcept
 Move assignment.

Friends

struct Helpers::PasswordAccess

Detailed Description

Shared, wiped container for passwords and raw key material.

Bytes live in Crypto-owned secure storage behind a Safe::Shared owner and are wiped when the last owner is destroyed. Copies share the same buffer. There is no public view of the raw bytes. Borrowed input is copied without wiping its source; mutable Safe text is copied and then wiped.

Note
MaybeSafe requires compatible compiler ABI and the Crypto module to remain loaded while passwords exist. Copy, move, assignment and destruction run out of line in Crypto; secure storage is released by its owning module. No caller allocation is adopted.
A borrowed std::string_view preserves its full length, including NUL bytes.
The caller remains responsible for wiping that source and any other copies.
A mutable Safe::String is ceded instead: construction copies its full length,
then overwrites and clears the source. No caller allocation is adopted.

String literals (Password("secret")) use const char*. They are copied and the source is not wiped: a literal lives in read-only storage. That form is for tests and non-secret placeholders, not for production secrets typed in source.

Raw bytes (const void* + StormByte::ByteSize) are copied and not wiped; the caller is responsible for the source buffer.

Constructor & Destructor Documentation

◆ Password() [1/7]

StormByte::Crypto::Secure::Password::Password ( )
noexcept

Empty password, suitable for Safe collections.

◆ Password() [2/7]

StormByte::Crypto::Secure::Password::Password ( std::string_view value)
explicit

Copy borrowed text into secure storage without wiping its source.

Parameters
valuePassword bytes, including embedded NUL bytes.
Note
The caller is responsible for wiping the source.

◆ Password() [3/7]

StormByte::Crypto::Secure::Password::Password ( StormByte::Safe::String & value)
explicit

From DLL-safe text.

Copies into secure storage and wipes value.

Parameters
valuePassword characters. Emptied and zeroed on return.
Note
Copies and wipes the full stored length, including embedded NUL bytes.

◆ Password() [4/7]

StormByte::Crypto::Secure::Password::Password ( const char * value)
explicit

From a C string up to the terminator.

The source is not wiped.

Parameters
valueNull-terminated password (including literals).

◆ Password() [5/7]

StormByte::Crypto::Secure::Password::Password ( const void * data,
StormByte::ByteSize size )

From raw bytes.

Exact size; no terminator is added. The source is not wiped.

Parameters
dataBytes, or nullptr if size is 0.
sizeNumber of bytes.

◆ Password() [6/7]

StormByte::Crypto::Secure::Password::Password ( const Password & other)

Copy constructor.

Shares the buffer.

Parameters
otherPassword to copy.

◆ Password() [7/7]

StormByte::Crypto::Secure::Password::Password ( Password && other)
noexcept

Move constructor.

Parameters
otherPassword to move.

◆ ~Password()

StormByte::Crypto::Secure::Password::~Password ( )

Destructor.

Wipes the buffer if this is the last owner.

Member Function Documentation

◆ Empty()

bool StormByte::Crypto::Secure::Password::Empty ( ) const
noexcept

Whether Size() is 0.

Returns
true if empty.

◆ operator bool()

StormByte::Crypto::Secure::Password::operator bool ( ) const
explicitnoexcept

true if the password is not empty.

Returns
Whether bytes are stored.

◆ operator!=()

bool StormByte::Crypto::Secure::Password::operator!= ( const Password & other) const
noexcept

Inequality.

Parameters
otherOther password.
Returns
true if not equal.

◆ operator=() [1/2]

Password & StormByte::Crypto::Secure::Password::operator= ( const Password & other)

Copy assignment.

Parameters
otherPassword to copy.
Returns
Reference to this password.

◆ operator=() [2/2]

Password & StormByte::Crypto::Secure::Password::operator= ( Password && other)
noexcept

Move assignment.

Parameters
otherPassword to move.
Returns
Reference to this password.

◆ operator==()

bool StormByte::Crypto::Secure::Password::operator== ( const Password & other) const
noexcept

Constant-time equality.

Parameters
otherOther password.
Returns
true if length and content match.

◆ Size()

StormByte::ByteSize StormByte::Crypto::Secure::Password::Size ( ) const
noexcept

Stored size in bytes.

Returns
Byte count.

◆ Helpers::PasswordAccess

friend struct Helpers::PasswordAccess
friend

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