pub struct SecretBox<S: Zeroize + ?Sized> { /* private fields */ }
Expand description
Wrapper type for values that contains secrets, which attempts to limit accidental exposure and ensure secrets are wiped from memory when dropped. (e.g. passwords, cryptographic keys, access tokens or other credentials)
Access to the secret inner value occurs through the ExposeSecret
or ExposeSecretMut
traits, which provide methods for accessing the inner secret value.
Implementations§
Source§impl<S: Zeroize + Default> SecretBox<S>
impl<S: Zeroize + Default> SecretBox<S>
Sourcepub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self
pub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self
Create a secret value using a function that can initialize the value in-place.
Source§impl<S: Zeroize + Clone> SecretBox<S>
impl<S: Zeroize + Clone> SecretBox<S>
Sourcepub fn init_with(ctr: impl FnOnce() -> S) -> Self
pub fn init_with(ctr: impl FnOnce() -> S) -> Self
Create a secret value using the provided function as a constructor.
The implementation makes an effort to zeroize the locally constructed value before it is copied to the heap, and constructing it inside the closure minimizes the possibility of it being accidentally copied by other code.
Note: using Self::new
or Self::init_with_mut
is preferable when possible,
since this method’s safety relies on empiric evidence and may be violated on some targets.
Sourcepub fn try_init_with<E>(ctr: impl FnOnce() -> Result<S, E>) -> Result<Self, E>
pub fn try_init_with<E>(ctr: impl FnOnce() -> Result<S, E>) -> Result<Self, E>
Same as Self::init_with
, but the constructor can be fallible.
Note: using Self::new
or Self::init_with_mut
is preferable when possible,
since this method’s safety relies on empyric evidence and may be violated on some targets.