pub struct LockedSecretString { /* private fields */ }Expand description
UTF-8 text stored in a private platform mapping locked against paging.
This wrapper delegates allocation, locking, dump/fork exclusion, canary
handling, growth, clearing, unlocking, and unmapping to LockedSecretVec.
It exposes only str/mut str access, so safe Rust cannot invalidate UTF-8.
Implementations§
Source§impl LockedSecretString
impl LockedSecretString
Sourcepub fn with_capacity(capacity: usize) -> Result<Self, MemoryLockError>
pub fn with_capacity(capacity: usize) -> Result<Self, MemoryLockError>
Allocate empty locked text storage with at least capacity UTF-8 bytes.
Sourcepub fn with_capacity_hardened_native(
capacity: usize,
) -> Result<Self, ProtectionError>
pub fn with_capacity_hardened_native( capacity: usize, ) -> Result<Self, ProtectionError>
Allocate locked text with the profile-hardened-native policy.
Sourcepub fn with_capacity_hardened_linux(
capacity: usize,
) -> Result<Self, ProtectionError>
pub fn with_capacity_hardened_linux( capacity: usize, ) -> Result<Self, ProtectionError>
Allocate locked text with the profile-hardened-linux 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 text storage 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, MemoryLockError>
pub fn from_secret_str(text: &str) -> Result<Self, MemoryLockError>
Copy UTF-8 text directly into a locked platform mapping.
Sourcepub fn from_string(text: String) -> Result<Self, MemoryLockError>
pub fn from_string(text: String) -> Result<Self, MemoryLockError>
Move an owned string through clear-on-drop staging into locked storage.
The original string allocation is volatile-cleared whether mapping setup succeeds or fails. The locked mapping necessarily receives a copy because it does not use the Rust global allocator.
Sourcepub fn from_locked_secret_vec(
inner: LockedSecretVec,
) -> Result<Self, SecretTextIntegrityError>
pub fn from_locked_secret_vec( inner: LockedSecretVec, ) -> Result<Self, SecretTextIntegrityError>
Wrap existing locked bytes without reallocating after UTF-8 validation.
Invalid input is cleared before core::str::Utf8Error is returned.
Sourcepub const fn locked_len(&self) -> usize
pub const fn locked_len(&self) -> usize
Length of the underlying locked mapping.
Sourcepub const fn is_memory_locked(&self) -> bool
pub const fn is_memory_locked(&self) -> bool
Returns true when the underlying mapping is locked against ordinary paging.
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 locked 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 locked 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<MemoryLockError>>
pub fn try_push_str( &mut self, text: &str, ) -> Result<(), SecretIntegrityError<MemoryLockError>>
Append UTF-8 text, preserving locked storage across growth.
Sourcepub fn try_replace_from_secret_str(
&mut self,
text: &str,
) -> Result<(), SecretIntegrityError<MemoryLockError>>
pub fn try_replace_from_secret_str( &mut self, text: &str, ) -> Result<(), SecretIntegrityError<MemoryLockError>>
Replace all text while preserving locked-storage semantics.
Sourcepub fn try_replace_from_string(
&mut self,
text: String,
) -> Result<(), SecretIntegrityError<MemoryLockError>>
pub fn try_replace_from_string( &mut self, text: String, ) -> Result<(), SecretIntegrityError<MemoryLockError>>
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 locked mapping 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 locked mapping, 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 underlying locked mapping canaries.
Sourcepub fn into_locked_secret_vec(self) -> LockedSecretVec
pub fn into_locked_secret_vec(self) -> LockedSecretVec
Return the locked byte container without reallocating.
Trait Implementations§
Source§impl ConstantTimeEq for LockedSecretString
Available on non-WebAssembly only.
impl ConstantTimeEq for LockedSecretString
Source§impl ConstantTimeEq for LockedSecretString
Available on crate feature memory-lock and non-WebAssembly only.
impl ConstantTimeEq for LockedSecretString
memory-lock and non-WebAssembly only.Source§impl ConstantTimeEq<str> for LockedSecretString
Available on non-WebAssembly only.
impl ConstantTimeEq<str> for LockedSecretString
Source§impl Debug for LockedSecretString
Available on crate feature memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.
impl Debug for LockedSecretString
memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.Source§impl From<LockedSecretString> for LockedSecretVec
Available on crate feature memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.
impl From<LockedSecretString> for LockedSecretVec
memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.Source§fn from(secret: LockedSecretString) -> Self
fn from(secret: LockedSecretString) -> Self
Source§impl SecureSanitize for LockedSecretString
Available on crate feature memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.
impl SecureSanitize for LockedSecretString
memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.Source§fn secure_sanitize(&mut self)
fn secure_sanitize(&mut self)
Source§impl TryFrom<LockedSecretVec> for LockedSecretString
Available on crate feature memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.
impl TryFrom<LockedSecretVec> for LockedSecretString
memory-lock and (Android, or DragonFly BSD, or FreeBSD, or iOS, or macOS, or NetBSD, or OpenBSD, or Windows, or Linux and (AArch64 or x86-64)) only.Source§type Error = SecretTextIntegrityError
type Error = SecretTextIntegrityError
Source§impl Zeroize for LockedSecretString
Available on crate feature memory-lock and non-WebAssembly only.
impl Zeroize for LockedSecretString
memory-lock and non-WebAssembly only.impl ZeroizeOnDrop for LockedSecretString
memory-lock and non-WebAssembly only.