Trait ProtectedInit

Source
pub trait ProtectedInit:
    ExposeProtected
    + From<SecureBox<Self::Target>>
    + Sized {
    // Provided methods
    fn init<F>(f: F) -> Self
       where F: FnOnce(SecureRef<&mut Self::Target>),
             Self::Target: Copy + FillBytes { ... }
    fn init_default<F>(f: F) -> Self
       where F: FnOnce(SecureRef<&mut Self::Target>),
             Self::Target: Default { ... }
    fn init_random<F>(rng: impl RngCore, f: F) -> Self
       where F: FnOnce(SecureRef<&mut Self::Target>),
             Self::Target: Copy + FillBytes { ... }
    fn init_take<F>(from: &mut Self::Target, f: F) -> Self
       where F: FnOnce(SecureRef<&mut Self::Target>),
             Self::Target: DefaultIsZeroes { ... }
    fn init_with<F>(f: F) -> Self
       where F: FnOnce() -> Self::Target,
             Self::Target: Sized { ... }
    fn try_init_with<F, E>(f: F) -> Result<Self, E>
       where F: FnOnce() -> Result<Self::Target, E>,
             Self::Target: Sized { ... }
    fn random(rng: impl RngCore) -> Self
       where Self::Target: Copy + FillBytes { ... }
    fn take(from: &mut Self::Target) -> Self
       where Self::Target: DefaultIsZeroes { ... }
}
Expand description

Initialize a protected container type for a sized value.

Provided Methods§

Source

fn init<F>(f: F) -> Self
where F: FnOnce(SecureRef<&mut Self::Target>), Self::Target: Copy + FillBytes,

For a concrete type implementing FillBytes, initialize with the standard indicator value and call the closure f with a mutable reference to the contained value before applying protections.

Source

fn init_default<F>(f: F) -> Self
where F: FnOnce(SecureRef<&mut Self::Target>), Self::Target: Default,

Initialize with the default value for Self::Target, and call the closure f with a mutable reference to the contained value before applying protections.

Source

fn init_random<F>(rng: impl RngCore, f: F) -> Self
where F: FnOnce(SecureRef<&mut Self::Target>), Self::Target: Copy + FillBytes,

Initialize with a randomized value for Self::Target, and call the closure f with a mutable reference to the contained value before applying protections.

Source

fn init_take<F>(from: &mut Self::Target, f: F) -> Self
where F: FnOnce(SecureRef<&mut Self::Target>), Self::Target: DefaultIsZeroes,

Initialize by copying the value contained in from and zeroizing the existing copy. Call the closure f with a mutable reference to the contained value before applying protections.

Source

fn init_with<F>(f: F) -> Self
where F: FnOnce() -> Self::Target, Self::Target: Sized,

Initialize by calling the closure f, store the resulting instance of Self::Target and apply protections.

Source

fn try_init_with<F, E>(f: F) -> Result<Self, E>
where F: FnOnce() -> Result<Self::Target, E>, Self::Target: Sized,

Initialize by calling the fallible closure f, store the resulting instance of Self::Target and apply protections. On failure, return the error type E.

Source

fn random(rng: impl RngCore) -> Self
where Self::Target: Copy + FillBytes,

Create a new protected instance containing a random value.

Source

fn take(from: &mut Self::Target) -> Self
where Self::Target: DefaultIsZeroes,

Create a new protected instance by copying and zeroizing an existing value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, W> ProtectedInit for W
where W: From<SecureBox<T>> + ExposeProtected<Target = T>,