pub struct SecureBox<T>where
T: Copy,{ /* private fields */ }
Expand description
A data type suitable for storing sensitive information such as passwords and private keys in memory, that implements:
- Automatic zeroing in
Drop
- Constant time comparison in
PartialEq
(does not short circuit on the first different character; but terminates instantly if strings have different length) - Outputting
***SECRET***
to prevent leaking secrets into logs infmt::Debug
andfmt::Display
- Automatic
mlock
to protect against leaking into swap (any unix) - Automatic
madvise(MADV_NOCORE/MADV_DONTDUMP)
to protect against leaking into core dumps (FreeBSD, DragonflyBSD, Linux)
Comparisons using the PartialEq
implementation are undefined behavior (and most likely wrong) if T
has any padding bytes.
Implementations§
Trait Implementations§
Source§impl<T> BorrowMut<T> for SecureBox<T>where
T: Copy,
impl<T> BorrowMut<T> for SecureBox<T>where
T: Copy,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Ord for SecureBox<T>
impl<T> Ord for SecureBox<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T> PartialOrd for SecureBox<T>where
T: Copy + PartialOrd,
impl<T> PartialOrd for SecureBox<T>where
T: Copy + PartialOrd,
impl<T> Eq for SecureBox<T>
impl<T> StructuralPartialEq for SecureBox<T>where
T: Copy,
Auto Trait Implementations§
impl<T> Freeze for SecureBox<T>
impl<T> RefUnwindSafe for SecureBox<T>where
T: RefUnwindSafe,
impl<T> Send for SecureBox<T>where
T: Send,
impl<T> Sync for SecureBox<T>where
T: Sync,
impl<T> Unpin for SecureBox<T>
impl<T> UnwindSafe for SecureBox<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more