Struct runtime::Guarded[][src]

pub struct Guarded<T: Bytes> { /* fields omitted */ }

A guarded type for protecting fixed-length secrets allocated on the heap.

Provides the following features and guarantees:

  • Causes segfault upon access without using a borrow.
  • Protected using mprotect:
    • Prot::NoAccess - when the box has no current borrows.
    • Prot::ReadOnly - when the box has at least one current immutable borrow.
    • Prot::ReadWrite - when the box has a current mutable borrow (can only have one at a time).
  • The allocated memory uses guard pages both proceeding and following the memory. Overflows and large underflows cause immediate termination of the program.
  • A canary proceeds the memory location to detect smaller underflows. The program will drop the underlying memory and terminate if detected.
  • The Memory is locked with mlock.
  • When the memory is freed, munlock is called.
  • The memory is zeroed when no longer in use via sodium_free.
  • Guarded types can be compared in constant time.
  • Guarded types can not be printed using Debug.
  • The interior data of a Guarded type may not be Clone.

Implementations

impl<T: Bytes> Guarded<T>[src]

pub fn new<F>(f: F) -> Self where
    F: FnOnce(&mut T), 
[src]

pub fn try_new<R, E, F>(f: F) -> Result<Self, E> where
    F: FnOnce(&mut T) -> Result<R, E>, 
[src]

pub fn size(&self) -> usize[src]

pub fn borrow(&self) -> Ref<'_, T>[src]

pub fn borrow_mut(&mut self) -> RefMut<'_, T>[src]

impl<T: Bytes + Randomized> Guarded<T>[src]

pub fn random() -> Self[src]

impl<T: Bytes + Zeroed> Guarded<T>[src]

pub fn zero() -> Self[src]

Trait Implementations

impl<T: Clone + Bytes> Clone for Guarded<T>[src]

impl<T: Bytes> Debug for Guarded<T>[src]

impl<T: Eq + Bytes> Eq for Guarded<T>[src]

impl<T: Bytes + Zeroed> From<&'_ mut T> for Guarded<T>[src]

impl<T: Bytes + ConstEq> PartialEq<Guarded<T>> for Guarded<T>[src]

impl<T: Bytes + Send> Send for Guarded<T>[src]

impl<T: Bytes> StructuralEq for Guarded<T>[src]

impl<T: Bytes + Sync> Sync for Guarded<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Guarded<T>

impl<T> Unpin for Guarded<T>

impl<T> UnwindSafe for Guarded<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.