pub struct BoundedSecretVec<const MAX: usize> { /* private fields */ }Expand description
Heap-allocated secret bytes constrained to a public maximum length.
This additive wrapper is intended for protocol and configuration trust
boundaries where unbounded dynamic secret allocation is unacceptable. With
the serde feature, every deserialization input form rejects more than
MAX bytes. Rejected owned buffers and partially decoded values are cleared
before they are released.
Implementations§
Source§impl<const MAX: usize> BoundedSecretVec<MAX>
impl<const MAX: usize> BoundedSecretVec<MAX>
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, SecretVecLimitError>
pub fn from_slice(bytes: &[u8]) -> Result<Self, SecretVecLimitError>
Copy a slice into bounded secret storage.
Sourcepub fn from_vec(bytes: Vec<u8>) -> Result<Self, SecretVecLimitError>
pub fn from_vec(bytes: Vec<u8>) -> Result<Self, SecretVecLimitError>
Take ownership of a vector after validating its length.
An oversized input allocation is volatile-cleared before the error is returned.
Sourcepub fn from_secret_vec(secret: SecretVec) -> Result<Self, SecretVecLimitError>
pub fn from_secret_vec(secret: SecretVec) -> Result<Self, SecretVecLimitError>
Convert an existing secret vector after validating its length.
An oversized input is cleared before the error is returned.
Sourcepub fn with_secret<R>(&self, inspect: impl FnOnce(&[u8]) -> R) -> R
pub fn with_secret<R>(&self, inspect: impl FnOnce(&[u8]) -> R) -> R
Run a closure with read-only access to the secret bytes.
Sourcepub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut [u8]) -> R) -> R
pub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut [u8]) -> R) -> R
Run a closure with mutable access to the initialized secret bytes.
Sourcepub fn extend_from_slice(
&mut self,
bytes: &[u8],
) -> Result<(), SecretVecLimitError>
pub fn extend_from_slice( &mut self, bytes: &[u8], ) -> Result<(), SecretVecLimitError>
Append bytes without permitting the configured limit to be exceeded.
Sourcepub fn replace_from_slice(
&mut self,
bytes: &[u8],
) -> Result<(), SecretVecLimitError>
pub fn replace_from_slice( &mut self, bytes: &[u8], ) -> Result<(), SecretVecLimitError>
Replace the current value after validating the replacement length.
Sourcepub fn clear_secret(&mut self)
pub fn clear_secret(&mut self)
Clear this value immediately with volatile writes.
Sourcepub fn into_secret_vec(self) -> SecretVec
pub fn into_secret_vec(self) -> SecretVec
Return the bounded value as an ordinary clear-on-drop secret vector.
Trait Implementations§
Source§impl<const MAX: usize> ConstantTimeEq for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> ConstantTimeEq for BoundedSecretVec<MAX>
alloc only.Source§impl<const MAX: usize> ConstantTimeEq for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> ConstantTimeEq for BoundedSecretVec<MAX>
alloc only.Source§impl<const MAX: usize> Debug for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> Debug for BoundedSecretVec<MAX>
alloc only.Source§impl<const MAX: usize> Default for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> Default for BoundedSecretVec<MAX>
alloc only.Source§impl<'de, const MAX: usize> Deserialize<'de> for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<'de, const MAX: usize> Deserialize<'de> for BoundedSecretVec<MAX>
alloc only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const MAX: usize> From<BoundedSecretVec<MAX>> for SecretVec
Available on crate feature alloc only.
impl<const MAX: usize> From<BoundedSecretVec<MAX>> for SecretVec
alloc only.Source§fn from(secret: BoundedSecretVec<MAX>) -> Self
fn from(secret: BoundedSecretVec<MAX>) -> Self
Source§impl<const MAX: usize> SecureSanitize for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> SecureSanitize for BoundedSecretVec<MAX>
alloc only.Source§fn secure_sanitize(&mut self)
fn secure_sanitize(&mut self)
Source§impl<const MAX: usize> Serialize for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> Serialize for BoundedSecretVec<MAX>
alloc only.Source§impl<const MAX: usize> Zeroize for BoundedSecretVec<MAX>
Available on crate feature alloc only.
impl<const MAX: usize> Zeroize for BoundedSecretVec<MAX>
alloc only.impl<const MAX: usize> ZeroizeOnDrop for BoundedSecretVec<MAX>
alloc only.