pub struct GuardedSecretString { /* private fields */ }Expand description
UTF-8 text stored between inaccessible platform guard pages.
This wrapper delegates guarded mapping ownership, optional memory locking,
canary handling, growth, clearing, and unmapping to GuardedSecretVec.
It exposes only str/mut str access.
Implementations§
Source§impl GuardedSecretString
impl GuardedSecretString
Sourcepub fn with_capacity(capacity: usize) -> Result<Self, GuardPageError>
pub fn with_capacity(capacity: usize) -> Result<Self, GuardPageError>
Allocate empty guarded text storage with at least capacity UTF-8 bytes.
Sourcepub fn with_capacity_guarded_native(
capacity: usize,
) -> Result<Self, ProtectionError>
pub fn with_capacity_guarded_native( capacity: usize, ) -> Result<Self, ProtectionError>
Allocate guarded text with the profile-guarded-native policy.
Sourcepub fn with_capacity_with_protection(
capacity: usize,
request: ProtectionRequest,
) -> Result<Self, ProtectionError>
pub fn with_capacity_with_protection( capacity: usize, request: ProtectionRequest, ) -> Result<Self, ProtectionError>
Allocate guarded text under an explicit runtime protection policy.
Sourcepub fn try_from_capacity_with_protection<E>(
capacity: usize,
request: ProtectionRequest,
fill: impl FnOnce(&mut [u8]) -> Result<usize, E>,
) -> Result<Self, ProtectedSecretTextFillError<E>>
pub fn try_from_capacity_with_protection<E>( capacity: usize, request: ProtectionRequest, fill: impl FnOnce(&mut [u8]) -> Result<usize, E>, ) -> Result<Self, ProtectedSecretTextFillError<E>>
Fill a runtime-length UTF-8 payload only after all required controls have been established.
The closure receives exactly capacity bytes and returns the number
initialized. Invalid UTF-8, partial fill failures, excessive lengths,
and canary corruption clear the mapping before returning an error.
Sourcepub fn try_from_capacity_bounded_with_protection<E>(
capacity: usize,
maximum: usize,
request: ProtectionRequest,
fill: impl FnOnce(&mut [u8]) -> Result<usize, E>,
) -> Result<Self, ProtectedSecretTextFillError<E>>
pub fn try_from_capacity_bounded_with_protection<E>( capacity: usize, maximum: usize, request: ProtectionRequest, fill: impl FnOnce(&mut [u8]) -> Result<usize, E>, ) -> Result<Self, ProtectedSecretTextFillError<E>>
Bounded policy-aware UTF-8 fill for untrusted capacities.
A capacity above maximum is rejected before mapping or invoking
fill.
Sourcepub fn try_from_exact_len_with_protection<E>(
len: usize,
request: ProtectionRequest,
fill: impl FnOnce(&mut [u8]) -> Result<(), E>,
) -> Result<Self, ProtectedSecretTextFillError<E>>
pub fn try_from_exact_len_with_protection<E>( len: usize, request: ProtectionRequest, fill: impl FnOnce(&mut [u8]) -> Result<(), E>, ) -> Result<Self, ProtectedSecretTextFillError<E>>
Fill an exact-length UTF-8 payload after required controls succeed.
Sourcepub fn from_secret_str(text: &str) -> Result<Self, GuardPageError>
pub fn from_secret_str(text: &str) -> Result<Self, GuardPageError>
Copy UTF-8 text directly into a guarded platform mapping.
Sourcepub fn from_string(text: String) -> Result<Self, GuardPageError>
pub fn from_string(text: String) -> Result<Self, GuardPageError>
Move an owned string through clear-on-drop staging into guarded storage.
Sourcepub fn locked_from_secret_str(text: &str) -> Result<Self, GuardPageError>
pub fn locked_from_secret_str(text: &str) -> Result<Self, GuardPageError>
Copy UTF-8 text into a guarded and memory-locked mapping.
Sourcepub fn locked_from_string(text: String) -> Result<Self, GuardPageError>
pub fn locked_from_string(text: String) -> Result<Self, GuardPageError>
Move an owned string through clear-on-drop staging into a guarded and memory-locked mapping.
Sourcepub fn from_guarded_secret_vec(
inner: GuardedSecretVec,
) -> Result<Self, SecretTextIntegrityError>
pub fn from_guarded_secret_vec( inner: GuardedSecretVec, ) -> Result<Self, SecretTextIntegrityError>
Wrap existing guarded bytes without reallocating after UTF-8 validation.
Invalid input is cleared before core::str::Utf8Error is returned.
Sourcepub const fn is_memory_locked(&self) -> bool
pub const fn is_memory_locked(&self) -> bool
Returns true when the writable guarded pages are memory locked.
Sourcepub const fn protection_report(&self) -> &ProtectionReport
pub const fn protection_report(&self) -> &ProtectionReport
Actual runtime protections established for the underlying mapping.
Sourcepub const fn protection_request(&self) -> ProtectionRequest
pub const fn protection_request(&self) -> ProtectionRequest
Runtime protection policy requested for the underlying mapping.
Sourcepub fn try_with_secret<R>(
&self,
inspect: impl FnOnce(&str) -> R,
) -> Result<R, SecretTextIntegrityError>
pub fn try_with_secret<R>( &self, inspect: impl FnOnce(&str) -> R, ) -> Result<R, SecretTextIntegrityError>
Run a closure with read-only access to the guarded secret text.
Sourcepub fn try_with_secret_mut<R>(
&mut self,
edit: impl FnOnce(&mut str) -> R,
) -> Result<R, SecretTextIntegrityError>
pub fn try_with_secret_mut<R>( &mut self, edit: impl FnOnce(&mut str) -> R, ) -> Result<R, SecretTextIntegrityError>
Run a closure with mutable access to the guarded secret text.
Sourcepub fn with_secret_or_panic<R>(&self, inspect: impl FnOnce(&str) -> R) -> R
pub fn with_secret_or_panic<R>(&self, inspect: impl FnOnce(&str) -> R) -> R
Run a closure with shared access, panicking on integrity or UTF-8 failure.
Sourcepub fn with_secret_mut_or_panic<R>(
&mut self,
edit: impl FnOnce(&mut str) -> R,
) -> R
pub fn with_secret_mut_or_panic<R>( &mut self, edit: impl FnOnce(&mut str) -> R, ) -> R
Run a closure with mutable access, panicking on integrity or UTF-8 failure.
Sourcepub fn try_push_str(
&mut self,
text: &str,
) -> Result<(), SecretIntegrityError<GuardPageError>>
pub fn try_push_str( &mut self, text: &str, ) -> Result<(), SecretIntegrityError<GuardPageError>>
Append UTF-8 text, preserving guarded and lock-state semantics.
Sourcepub fn try_replace_from_secret_str(
&mut self,
text: &str,
) -> Result<(), SecretIntegrityError<GuardPageError>>
pub fn try_replace_from_secret_str( &mut self, text: &str, ) -> Result<(), SecretIntegrityError<GuardPageError>>
Replace all text while preserving guarded and lock-state semantics.
Sourcepub fn try_replace_from_string(
&mut self,
text: String,
) -> Result<(), SecretIntegrityError<GuardPageError>>
pub fn try_replace_from_string( &mut self, text: String, ) -> Result<(), SecretIntegrityError<GuardPageError>>
Replace all text from an owned string and clear the source allocation.
Sourcepub fn clear_secret(&mut self)
pub fn clear_secret(&mut self)
Clear the full writable guarded region and reset the text length.
Sourcepub fn try_clear_secret_and_flush(
&mut self,
) -> Result<CacheFlushReport, CacheFlushError>
pub fn try_clear_secret_and_flush( &mut self, ) -> Result<CacheFlushReport, CacheFlushError>
Clear the writable guarded region, then flush its cache lines.
Sourcepub fn try_constant_time_eq(
&self,
other: &str,
) -> Result<bool, CanaryCorruptedError>
pub fn try_constant_time_eq( &self, other: &str, ) -> Result<bool, CanaryCorruptedError>
Compare against UTF-8 text without early exit for equal-length inputs.
Sourcepub fn constant_time_eq_or_panic(&self, other: &str) -> bool
pub fn constant_time_eq_or_panic(&self, other: &str) -> bool
Compare after integrity verification, panicking on canary corruption.
Sourcepub fn verify_integrity(&self) -> Result<(), CanaryCorruptedError>
pub fn verify_integrity(&self) -> Result<(), CanaryCorruptedError>
Verify the guarded mapping canaries.
Sourcepub fn into_guarded_secret_vec(self) -> GuardedSecretVec
pub fn into_guarded_secret_vec(self) -> GuardedSecretVec
Return the guarded byte container without reallocating.
Trait Implementations§
Source§impl ConstantTimeEq for GuardedSecretString
impl ConstantTimeEq for GuardedSecretString
Source§impl ConstantTimeEq for GuardedSecretString
Available on crate feature guard-pages and not (miri) only.
impl ConstantTimeEq for GuardedSecretString
guard-pages and not (miri) only.Source§impl ConstantTimeEq<str> for GuardedSecretString
impl ConstantTimeEq<str> for GuardedSecretString
Source§impl Debug for GuardedSecretString
Available on crate feature guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.
impl Debug for GuardedSecretString
guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.Source§impl From<GuardedSecretString> for GuardedSecretVec
Available on crate feature guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.
impl From<GuardedSecretString> for GuardedSecretVec
guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.Source§fn from(secret: GuardedSecretString) -> Self
fn from(secret: GuardedSecretString) -> Self
Source§impl SecureSanitize for GuardedSecretString
Available on crate feature guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.
impl SecureSanitize for GuardedSecretString
guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.Source§fn secure_sanitize(&mut self)
fn secure_sanitize(&mut self)
Source§impl TryFrom<GuardedSecretVec> for GuardedSecretString
Available on crate feature guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.
impl TryFrom<GuardedSecretVec> for GuardedSecretString
guard-pages and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) and not (miri) only.Source§type Error = SecretTextIntegrityError
type Error = SecretTextIntegrityError
Source§impl Zeroize for GuardedSecretString
Available on crate feature guard-pages and not (miri) only.
impl Zeroize for GuardedSecretString
guard-pages and not (miri) only.impl ZeroizeOnDrop for GuardedSecretString
guard-pages and not (miri) only.