6#include <portals/secure_string.hpp>
7#include <portals/widget_types.hpp>
18 std::optional<SecureStringAccessFailure<E>>
access;
22struct PasswordValueAccess;
23#if defined(PORTALS_SECURE_STRING_TESTING)
24struct SecureStringTestHooks;
77 [[nodiscard]] std::size_t
size() const noexcept;
79 [[nodiscard]]
bool empty() const noexcept;
90 [[nodiscard]]
bool operator==(const
PasswordValue &other) const noexcept = default;
107 requires detail::SecretCallback<F>
110 std::invoke_result_t<std::decay_t<F> &,
SecretView>>::Error>> {
111 return accessState(state_, std::forward<F>(callback));
118 requires detail::SecretCallback<F>
119 static auto accessState(std::shared_ptr<State> state, F &&callback)
121 std::invoke_result_t<std::decay_t<F> &,
SecretView>>::Error>> {
122 using Return = std::invoke_result_t<std::decay_t<F> &,
SecretView>;
127 return std::unexpected(Failure{
132 if (
auto error = checkOwner(state)) {
133 return std::unexpected(Failure{error, {}});
136 auto result = protectedStorage(state).withPlaintext(std::forward<F>(callback));
138 auto cleanup = finishAccess(state);
141 auto failure = result ? AccessFailure{} : std::move(result.error());
143 failure.cleanup.add(cleanup->primary);
144 failure.cleanup.append(cleanup->cleanup);
146 return std::unexpected(Failure{{}, std::move(failure)});
150 return std::unexpected(Failure{{}, std::move(result.error())});
156 explicit PasswordValue(std::shared_ptr<State> state)
noexcept;
157 static std::expected<PasswordValue, SecureStringFailure> freeze(SecureString &&value, SecureStringOptions
options);
158 static std::optional<TreeError> checkOwner(
const std::shared_ptr<State> &state)
noexcept;
159 static SecureString &protectedStorage(
const std::shared_ptr<State> &state)
noexcept;
160 static std::optional<SecureStringFailure> finishAccess(
const std::shared_ptr<State> &state)
noexcept;
162 std::shared_ptr<State> state_;
163 friend struct detail::PasswordValueAccess;
169struct PasswordValueAccess {
177 requires SecretCallback<F>
178 static auto borrowOwned(PasswordValue value, F &&callback) {
179 return PasswordValue::accessState(std::move(value.state_), std::forward<F>(callback));
192 [[nodiscard]]
static std::expected<PasswordValue, PasswordValueAccessFailure<SecureStringFailure>>
193 replace(
const PasswordValue &source, std::size_t first, std::size_t last, std::string_view insertion);
194#if defined(PORTALS_SECURE_STRING_TESTING)
195 static void attachTestHooks(
const PasswordValue &value, SecureStringTestHooks &hooks)
noexcept;
SecureStringOptions options() const noexcept
static std::expected< PasswordValue, SecureStringFailure > create(std::string_view bytes={}, SecureStringOptions options={})
Establish mandatory native protection before copying opaque input bytes.
bool empty() const noexcept
PasswordValue() noexcept=default
Construct an unavailable identity without allocating protected storage.
bool available() const noexcept
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.
Definition password_value.hpp:108
SecureStringCapabilities capabilities() const noexcept
std::size_t size() const noexcept
Synchronous read-only byte borrow, valid only during its callback.
Definition secure_string.hpp:195
Public Portals API.
Definition action.hpp:8
@ BORROW
Admit plaintext access, capture a callable or invoke its callback.
Definition secure_string.hpp:78
@ UNAVAILABLE
The handle is moved-from, closed or invalidated by a security failure.
Definition secure_string.hpp:110
Independent ownership and protected-access failures, without secret diagnostics.
Definition password_value.hpp:14
std::optional< SecureStringAccessFailure< E > > access
Protected-storage, callback and cleanup diagnostics, retained independently.
Definition password_value.hpp:18
std::optional< TreeError > ownership
Ownership/admission rejection; the callback was neither captured nor invoked.
Definition password_value.hpp:16
Callback and cleanup diagnostics; opaque user errors are never logged.
Definition secure_string.hpp:223
Applied guarantees, rather than potential platform features.
Definition secure_string.hpp:52
A primary failure and independently preserved bounded cleanup diagnostics.
Definition secure_string.hpp:182
Requested mandatory guarantees, established even for an empty value.
Definition secure_string.hpp:38