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 + ?Sized> SecretBox<S>
impl<S: Zeroize + Default + ?Sized> 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 + ?Sized> SecretBox<S>
impl<S: Zeroize + Clone + ?Sized> 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.
Trait Implementations§
source§impl<S> Clone for SecretBox<S>where
S: CloneableSecret,
impl<S> Clone for SecretBox<S>where
S: CloneableSecret,
source§impl<'de, T> Deserialize<'de> for SecretBox<T>
Available on crate feature serde only.
impl<'de, T> Deserialize<'de> for SecretBox<T>
serde 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<S: Zeroize + ?Sized> ExposeSecret<S> for SecretBox<S>
impl<S: Zeroize + ?Sized> ExposeSecret<S> for SecretBox<S>
source§fn expose_secret(&self) -> &S
fn expose_secret(&self) -> &S
source§impl<S: Zeroize + ?Sized> ExposeSecretMut<S> for SecretBox<S>
impl<S: Zeroize + ?Sized> ExposeSecretMut<S> for SecretBox<S>
source§fn expose_secret_mut(&mut self) -> &mut S
fn expose_secret_mut(&mut self) -> &mut S
impl<S: Zeroize + ?Sized> ZeroizeOnDrop for SecretBox<S>
Auto Trait Implementations§
impl<S> Freeze for SecretBox<S>where
S: ?Sized,
impl<S> RefUnwindSafe for SecretBox<S>where
S: RefUnwindSafe + ?Sized,
impl<S> Send for SecretBox<S>
impl<S> Sync for SecretBox<S>
impl<S> Unpin for SecretBox<S>where
S: ?Sized,
impl<S> UnwindSafe for SecretBox<S>where
S: UnwindSafe + ?Sized,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)