Struct zerodrop::ZeroDrop [] [src]

pub struct ZeroDrop<T>(_)
where
    T: Copy
;

Zeroing drop wrapper type for Copy type.

Assuming T: Copy, a ZeroDrop<T> wraps a Box<T> and zeros it when dropped. We must use Box because LLVM moves data on the stack willy nilly.

let p : *const [u8; 32];
let s = zerodrop::ZeroDrop::new_copy(&[3u8; 32]);  
p = &*s;
std::mem::drop(s);
unsafe { assert_eq!(*p,[0u8; 32]); }

We recommend abstracting usage of ZeroDrop as follows because ZeroDrop does not mlock data. rust,ignore type Secret<T> = ZeroDrop<T> where T: Copy+Default; We similarly encurage wrapping ZeroDrop yourself so as to limit where and how secret data can be used in your code, including avoiding any trait magic that seems overly subtle. rust,ignore struct MySecret(pub ZeroDrop<[u8; 32]>);

Methods

impl<T> ZeroDrop<T> where
    T: Copy
[src]

Create a ZeroDrop<T> for a T: Copy consisting of a Box<T> that will be zeroed when dropped.

Insecure as t likely gets placed on the stack

Use provided Box<T>

Secure but unsafe

Allocate box and copy data into it from reference

Trait Implementations

impl<T: Debug> Debug for ZeroDrop<T> where
    T: Copy
[src]

Formats the value using the given formatter.

impl<T> Drop for ZeroDrop<T> where
    T: Copy
[src]

Zero a ZeroDrop<T> when dropped.

A method called when the value goes out of scope. Read more

impl<T> Default for ZeroDrop<T> where
    T: Copy + Default
[src]

Returns the "default value" for a type. Read more

impl<T> Clone for ZeroDrop<T> where
    T: Copy
[src]

Clone the underlying Box

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> Deref for ZeroDrop<T> where
    T: Copy
[src]

Delegate Deref to Box

The resulting type after dereferencing

The method called to dereference a value

impl<T> DerefMut for ZeroDrop<T> where
    T: Copy
[src]

Delegate DerefMut to Box

The method called to mutably dereference a value

impl<T> AsRef<T> for ZeroDrop<T> where
    T: Copy
[src]

Delegate AsRef<_> to Box

Performs the conversion.

impl<T> AsMut<T> for ZeroDrop<T> where
    T: Copy
[src]

Delegate AsMut<_> to Box

Performs the conversion.

impl<T> Borrow<T> for ZeroDrop<T> where
    T: Copy
[src]

Delegate Borrow<_> to Box

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for ZeroDrop<T> where
    T: Copy
[src]

Delegate BorrowMut<_> to Box

Mutably borrows from an owned value. Read more