secrecy

Struct SecretBox

Source
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 + ?Sized> SecretBox<S>

Source

pub fn new(boxed_secret: Box<S>) -> Self

Create a secret value using a pre-boxed value.

Source§

impl<S: Zeroize + Default> SecretBox<S>

Source

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>

Source

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.

Source

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,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Zeroize + ?Sized> Debug for SecretBox<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Zeroize + Default> Default for SecretBox<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S: Zeroize + ?Sized> Drop for SecretBox<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<S: Zeroize + ?Sized> ExposeSecret<S> for SecretBox<S>

Source§

fn expose_secret(&self) -> &S

Expose secret: this is the only method providing access to a secret.
Source§

impl<S: Zeroize + ?Sized> ExposeSecretMut<S> for SecretBox<S>

Source§

fn expose_secret_mut(&mut self) -> &mut S

Expose secret: this is the only method providing access to a secret.
Source§

impl<S: Zeroize + ?Sized> From<Box<S>> for SecretBox<S>

Source§

fn from(source: Box<S>) -> Self

Converts to this type from the input type.
Source§

impl<S: Zeroize + ?Sized> Zeroize for SecretBox<S>

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

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>
where S: Send + ?Sized,

§

impl<S> Sync for SecretBox<S>
where S: Sync + ?Sized,

§

impl<S> Unpin for SecretBox<S>
where S: ?Sized,

§

impl<S> UnwindSafe for SecretBox<S>
where S: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.