Struct Secured

Source
#[repr(align(4096))]
pub struct Secured<T: Copy>(/* private fields */);
Expand description

A stack-allocated value protected by locking its virtual memory page in physical memory.

Implementations§

Source§

impl<T: Copy> Secured<T>

Source

pub fn borrow_default<F, R>(&mut self, f: F) -> R
where F: FnOnce(SecureRef<&mut T>) -> R, T: Default,

For an existing Secured instance, fill with the default value of T and call the closure f with a mutable reference.

Source

pub fn borrow_random<F, R>(&mut self, rng: impl RngCore, f: F) -> R
where F: FnOnce(SecureRef<&mut T>) -> R, T: FillBytes,

For an existing Secured instance, fill with a set of random bytes, then return the result of calling the closure f with a mutable reference.

Source

pub fn borrow_take<F, R>(&mut self, take: &mut T, f: F) -> R
where F: FnOnce(SecureRef<&mut T>) -> R, T: DefaultIsZeroes,

For an existing Secured instance, fill with the default value of T and call the closure f with a mutable reference.

Source

pub fn borrow_uninit<F, R>(&mut self, f: F) -> R
where F: FnOnce(SecureRef<&mut MaybeUninit<T>>) -> R,

For an existing Secured instance, call a closure f with a mutable reference to an uninitialized T.

Source

pub fn default<F, R>(f: F) -> R
where F: FnOnce(SecureRef<&mut T>) -> R, T: Default,

Fill a Secured with the default value of T and return the result of calling the closure f with a mutable reference.

Source

pub fn random<F, R>(rng: impl RngCore, f: F) -> R
where F: FnOnce(SecureRef<&mut T>) -> R, T: FillBytes,

Fill a Secured with a set of random bytes, then return the result of calling the closure f with a mutable reference.

Source

pub fn take<F, R>(take: &mut T, f: F) -> R
where F: FnOnce(SecureRef<&mut T>) -> R, T: DefaultIsZeroes,

Fill a Secured by coping an existing value of type T, and zeroize the original copy. Return the result of calling the closure f with a mutable reference.

Source

pub fn uninit<F, R>(f: F) -> R
where F: FnOnce(SecureRef<&mut MaybeUninit<T>>) -> R,

Call the closure f with a mutable reference to an uninitialized T.

Source§

impl<const N: usize> Secured<[u8; N]>

Source

pub fn borrow_bytes<F, R>(&mut self, f: F) -> R
where F: FnOnce(SecureRef<&mut [u8; N]>) -> R,

For an existing Secured instance, call a closure with a mutable reference to an array of bytes. The values of the bytes are initialized to a standard indicator value.

Source

pub fn bytes<F, R>(f: F) -> R
where F: FnOnce(SecureRef<&mut [u8; N]>) -> R,

Call the closure f with a mutable reference to an array of bytes. The values of the bytes are initialized to a standard indicator value.

Trait Implementations§

Source§

impl<T: Copy> ConstDefault for Secured<T>

Source§

const DEFAULT: Self

The constant default value.
Source§

impl<T: Copy> Debug for Secured<T>

Source§

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

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

impl<T: Copy> Default for Secured<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for Secured<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Secured<T>
where T: RefUnwindSafe,

§

impl<T> Send for Secured<T>
where T: Send,

§

impl<T> Sync for Secured<T>
where T: Sync,

§

impl<T> Unpin for Secured<T>
where T: Unpin,

§

impl<T> UnwindSafe for Secured<T>
where T: UnwindSafe,

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.