|
|
| SecureString (const SecureString &)=delete |
| | Copying secret ownership/bytes is not supported.
|
|
SecureString & | operator= (const SecureString &)=delete |
| | Copy assignment is not supported.
|
| | SecureString (SecureString &&other) noexcept |
| | Transfer the ownership handle and its existing busy state, without copying bytes.
|
| SecureString & | operator= (SecureString &&other) noexcept |
| | Detach the old destination and transfer the source handle; self-move is a no-op. An active lease keeps detached destination storage alive until checked finish.
|
|
| ~SecureString () noexcept |
| | Detach ownership; wipe/release immediately or after the final active lease.
|
| std::expected< void, SecureStringFailure > | assign (std::string_view bytes) |
| | Replace bytes via an exact-length candidate; preparation failure preserves the old value.
|
| std::expected< void, SecureStringFailure > | append (std::string_view bytes) |
| | Append bytes via an exact-length candidate; no exponential growth or string intermediate.
|
| std::expected< void, SecureStringFailure > | clear () |
| | Replace with a valid empty value under the same requested policy.
|
| std::expected< void, SecureStringFailure > | close () noexcept |
| | Wipe and release; idempotent after success, retryable after release failure, BUSY during borrow.
|
| std::size_t | size () const noexcept |
| bool | empty () const noexcept |
| bool | available () const noexcept |
| SecureStringCapabilities | capabilities () const noexcept |
template<class F>
requires detail::SecretCallback<F> |
| auto | withPlaintext (F &&callback) -> std::expected< void, SecureStringAccessFailure< typename detail::SecretCallbackResult< std::invoke_result_t< std::decay_t< F > &, SecretView > >::Error > > |
| | Invoke an owned synchronous callable, then restore protection or retire detached storage.
|
Move-only bounded secret storage with checked synchronous plaintext access.
Native storage has adjacent inaccessible guard pages and an always-RW payload. Windows and Linux encrypt idle bytes by default. Windows uses SAME_PROCESS; Linux uses authenticated encryption and a separate guarded key page. Optional page locking and Linux dump exclusion cover both key and payload pages. WIPE_ONLY requires explicit encryption opt-out, uses heap storage and rejects lock/dump/encryption requests. Unsupported mandatory guarantees fail without a downgrade, including on WASM. Full accessible capacity is wiped before release; a failed release retains zeroed metadata for close() retry. A destructor retries release twice and may leak zeroed pages if the OS refuses both attempts.
Candidate allocation/capability failure preserves the old value. Ambiguous crypto failure wipes the affected payload and makes that value unavailable. Replacement failure after old-storage retirement never resurrects old bytes.
This does not protect against a debugger, hostile code in the process, host, keylogger, live plaintext access or external copies. Length is not concealed. Operations, moves and destruction require caller synchronization. A callback may move/destroy the external owner; its lease stays alive. Checked mutation and nested borrowing of that same storage fail BUSY, including no-op inputs.
template<class F>
requires detail::SecretCallback<F>
| auto portals::SecureString::withPlaintext |
( |
F && | callback | ) |
-> std::expected< void, SecureStringAccessFailure< typename detail::SecretCallbackResult< std::invoke_result_t< std::decay_t< F > &, SecretView > >::Error > > |
|
inlinenodiscard |
Invoke an owned synchronous callable, then restore protection or retire detached storage.
- Template Parameters
-
| F | Copyable lvalue or movable rvalue callable returning void or expected<void,E>. |
- Parameters
-
| callback | Callable copied/moved after the lease and busy gate, before decryption. |
- Returns
- Callback error/exception and cleanup failure are preserved independently.
E must be owning and nothrow movable; direct pointers, reference wrappers, SecretView and standard borrowed ranges/views are rejected. Custom E and callable captures retain their explicit caller lifetime obligations. Capture bad_alloc maps to NO_MEMORY; other exceptions map to CALLBACK_FAILED. Neither exception text nor opaque E is formatted. No owner access occurs after capture.