Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::PasswordValue Class Reference

Copyable identity of immutable logical bytes in protected native storage. More...

#include <password_value.hpp>

Public Member Functions

 PasswordValue () noexcept=default
 Construct an unavailable identity without allocating protected storage.
 PasswordValue (const PasswordValue &other) noexcept=default
 Retain the same identity without copying plaintext.
PasswordValue & operator= (const PasswordValue &other) noexcept=default
 Replace this handle with the same identity as other.
 PasswordValue (PasswordValue &&other) noexcept=default
 Transfer identity, leaving other unavailable.
PasswordValue & operator= (PasswordValue &&other) noexcept
 Transfer identity, leaving other unavailable except on self-move.
 ~PasswordValue () noexcept=default
 Release this identity; the last owner wipes/releases protected storage.
std::size_t size () const noexcept
bool empty () const noexcept
bool available () const noexcept
SecureStringOptions options () const noexcept
SecureStringCapabilities capabilities () const noexcept
bool operator== (const PasswordValue &other) const noexcept=default
 Compare identities without borrowing, decrypting or comparing secret bytes.
template<class F>
requires detail::SecretCallback<F>
auto withPlaintext (F &&callback) const -> std::expected< void, PasswordValueAccessFailure< typename detail::SecretCallbackResult< std::invoke_result_t< std::decay_t< F > &, SecretView > >::Error > >
 Borrow read-only plaintext synchronously on the creating thread.

Static Public Member Functions

static std::expected< PasswordValue, SecureStringFailure > create (std::string_view bytes={}, SecureStringOptions options={})
 Establish mandatory native protection before copying opaque input bytes.

Friends

struct detail::PasswordValueAccess

Detailed Description

Copyable identity of immutable logical bytes in protected native storage.

Copies share one protected value; equal bytes created separately have different identities. Retained snapshots can outlive a widget or model. Replacing the last external handle during a callback does not end its active lease. Copy, move, comparison and destruction do not allocate or invoke application/UI callbacks.

Creation requires native guarded storage and idle encryption, without fallback. Bytes are opaque, including zeroes; Unicode validation belongs to the editor. Only the creating thread may borrow plaintext. Separate handles and immutable metadata may be retained on other threads; simultaneous access to the same handle still requires caller synchronization. A cryptographic failure can make every shared identity unavailable; immutable logical content does not promise immutable availability. Input bytes, callback copies and escaped views remain the caller's responsibility; length is public metadata.

Constructor & Destructor Documentation

◆ PasswordValue() [1/2]

portals::PasswordValue::PasswordValue ( const PasswordValue & other)
defaultnoexcept

Retain the same identity without copying plaintext.

Parameters
otherIdentity whose protected storage is retained.

◆ PasswordValue() [2/2]

portals::PasswordValue::PasswordValue ( PasswordValue && other)
defaultnoexcept

Transfer identity, leaving other unavailable.

Parameters
otherSource handle; an active borrow remains valid.

Member Function Documentation

◆ available()

bool portals::PasswordValue::available ( ) const
nodiscardnoexcept
Returns
Whether the shared protected value remains usable; safe from other threads.

◆ capabilities()

SecureStringCapabilities portals::PasswordValue::capabilities ( ) const
nodiscardnoexcept
Returns
Guarantees established at creation, or all false without an identity; check available() separately.

◆ create()

std::expected< PasswordValue, SecureStringFailure > portals::PasswordValue::create ( std::string_view bytes = {},
SecureStringOptions options = {} )
staticnodiscard

Establish mandatory native protection before copying opaque input bytes.

Parameters
bytesBorrowed bytes copied synchronously, including embedded zeroes.
optionsMandatory policy and byte bound; weaker storage/encryption is rejected.
Returns
A new identity, including valid empty values, or secret-free failure diagnostics.

◆ empty()

bool portals::PasswordValue::empty ( ) const
nodiscardnoexcept
Returns
Whether the original logical byte count is zero; this does not establish availability.

◆ operator=() [1/2]

PasswordValue & portals::PasswordValue::operator= ( const PasswordValue & other)
defaultnoexcept

Replace this handle with the same identity as other.

Parameters
otherIdentity whose protected storage is retained.
Returns
This handle.

◆ operator=() [2/2]

PasswordValue & portals::PasswordValue::operator= ( PasswordValue && other)
noexcept

Transfer identity, leaving other unavailable except on self-move.

Parameters
otherSource handle; an active borrow remains valid.
Returns
This handle.

◆ operator==()

bool portals::PasswordValue::operator== ( const PasswordValue & other) const
nodiscarddefaultnoexcept

Compare identities without borrowing, decrypting or comparing secret bytes.

Parameters
otherIdentity to compare; all unavailable default/moved-from handles share a null identity.
Returns
Whether both handles retain the same identity.

◆ options()

SecureStringOptions portals::PasswordValue::options ( ) const
nodiscardnoexcept
Returns
Creation policy, or default options for a default/moved-from handle.

◆ size()

std::size_t portals::PasswordValue::size ( ) const
nodiscardnoexcept
Returns
Original logical byte count, or zero for a default/moved-from handle.

◆ withPlaintext()

template<class F>
requires detail::SecretCallback<F>
auto portals::PasswordValue::withPlaintext ( F && callback) const -> std::expected< void, PasswordValueAccessFailure< typename detail::SecretCallbackResult< std::invoke_result_t< std::decay_t< F > &, SecretView > >::Error > >
inlinenodiscard

Borrow read-only plaintext synchronously on the creating thread.

Template Parameters
FCopyable lvalue or movable rvalue callable returning void or expected<void,E>.
Parameters
callbackCallable owned under the SecureString busy gate before decryption.
Returns
Independent ownership, storage, typed callback and cleanup failures.

State is retained before callable capture or invocation, either of which may destroy the external owner. Wrong-thread calls do not touch protected storage or capture the callable. Nested access to the same identity returns BUSY. If this frame is the last owner after invocation, it checks final retirement. Other retained handles use ordinary noexcept destructor cleanup when released; a concurrent release after the ownership check can also take that path. Views are valid only during invocation. Callback and cleanup guarantees, including owning error constraints, are those of SecureString::withPlaintext.


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