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.
fn new_insecure(t: T) -> ZeroDrop<T>
Insecure as t
likely gets placed on the stack
fn new_box(b: Box<T>) -> ZeroDrop<T>
Use provided Box<T>
unsafe fn new_uninitialized() -> ZeroDrop<T>
Secure but unsafe
fn new_copy(t: &T) -> ZeroDrop<T>
Allocate box and copy data into it from reference
unsafe fn zero_out(&mut self)
fn new_zeroed() -> ZeroDrop<T>
Trait Implementations
impl<T: Debug> Debug for ZeroDrop<T> where T: Copy
[src]
impl<T> Drop for ZeroDrop<T> where T: Copy
[src]
Zero a ZeroDrop<T>
when dropped.
impl<T> Default for ZeroDrop<T> where T: Copy + Default
[src]
impl<T> Clone for ZeroDrop<T> where T: Copy
[src]
Clone
the underlying Box
fn clone(&self) -> ZeroDrop<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &ZeroDrop<T>)
Performs copy-assignment from source
. Read more
impl<T> Deref for ZeroDrop<T> where T: Copy
[src]
Delegate Deref
to Box
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<T> DerefMut for ZeroDrop<T> where T: Copy
[src]
Delegate DerefMut
to Box
fn deref_mut(&mut self) -> &mut T
The method called to mutably dereference a value
impl<T, U> AsRef<U> for ZeroDrop<T> where T: Copy + AsRef<U>
[src]
Delegate AsRef<_>
to Box
fn as_ref(&self) -> &U
Performs the conversion.
impl<T, U> AsMut<U> for ZeroDrop<T> where T: Copy + AsMut<U>
[src]
Delegate AsMut<_>
to Box
fn as_mut(&mut self) -> &mut U
Performs the conversion.
impl<T> Borrow<T> for ZeroDrop<T> where T: Copy
[src]
Delegate Borrow<_>
to Box
impl<T> BorrowMut<T> for ZeroDrop<T> where T: Copy
[src]
Delegate BorrowMut<_>
to Box
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more