pub struct SecureArray<T, const LENGTH: usize>{ /* 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§
Source§impl<T, const LENGTH: usize> SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> SecureArray<T, LENGTH>
pub fn new(content: [T; LENGTH]) -> Self
Sourcepub fn unsecure_mut(&mut self) -> &mut [T]
pub fn unsecure_mut(&mut self) -> &mut [T]
Mutably borrow the contents of the string.
Trait Implementations§
Source§impl<T, const LENGTH: usize> BorrowMut<[T]> for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> BorrowMut<[T]> for SecureArray<T, LENGTH>
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, const LENGTH: usize> Debug for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> Debug for SecureArray<T, LENGTH>
Source§impl<T, const LENGTH: usize> Display for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> Display for SecureArray<T, LENGTH>
Source§impl<T, const LENGTH: usize> Drop for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> Drop for SecureArray<T, LENGTH>
Source§impl<T, const LENGTH: usize> From<[T; LENGTH]> for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> From<[T; LENGTH]> for SecureArray<T, LENGTH>
Source§fn from(s: [T; LENGTH]) -> Self
fn from(s: [T; LENGTH]) -> Self
Converts to this type from the input type.
Source§impl<T, const LENGTH: usize> Hash for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> Hash for SecureArray<T, LENGTH>
Source§impl<T, U, const LENGTH: usize> Index<U> for SecureArray<T, LENGTH>
impl<T, U, const LENGTH: usize> Index<U> for SecureArray<T, LENGTH>
Source§impl<T, const LENGTH: usize> Ord for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> Ord for SecureArray<T, LENGTH>
Source§fn cmp(&self, other: &SecureArray<T, LENGTH>) -> Ordering
fn cmp(&self, other: &SecureArray<T, LENGTH>) -> Ordering
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, const LENGTH: usize> PartialEq for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> PartialEq for SecureArray<T, LENGTH>
Source§impl<T, const LENGTH: usize> PartialOrd for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> PartialOrd for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> Eq for SecureArray<T, LENGTH>
impl<T, const LENGTH: usize> StructuralPartialEq for SecureArray<T, LENGTH>
Auto Trait Implementations§
impl<T, const LENGTH: usize> Freeze for SecureArray<T, LENGTH>where
T: Freeze,
impl<T, const LENGTH: usize> RefUnwindSafe for SecureArray<T, LENGTH>where
T: RefUnwindSafe,
impl<T, const LENGTH: usize> Send for SecureArray<T, LENGTH>where
T: Send,
impl<T, const LENGTH: usize> Sync for SecureArray<T, LENGTH>where
T: Sync,
impl<T, const LENGTH: usize> Unpin for SecureArray<T, LENGTH>where
T: Unpin,
impl<T, const LENGTH: usize> UnwindSafe for SecureArray<T, LENGTH>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