Struct secure_string::SecureArray
source · pub struct SecureArray<T, const LENGTH: usize>where
T: Sized + Copy + Zeroize,{ /* 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>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
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> Borrow<[T]> for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> Borrow<[T]> for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
source§impl<T, const LENGTH: usize> BorrowMut<[T]> for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> BorrowMut<[T]> for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
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>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> Debug for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
source§impl<T, const LENGTH: usize> Display for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> Display for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
source§impl<T, const LENGTH: usize> From<[T; LENGTH]> for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> From<[T; LENGTH]> for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
source§fn from(s: [T; LENGTH]) -> Self
fn from(s: [T; LENGTH]) -> Self
Converts to this type from the input type.
source§impl<T, U, const LENGTH: usize> Index<U> for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize,
[T; LENGTH]: Index<U>,
impl<T, U, const LENGTH: usize> Index<U> for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize, [T; LENGTH]: Index<U>,
source§impl<T, const LENGTH: usize> PartialEq for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize + NoPaddingBytes,
impl<T, const LENGTH: usize> PartialEq for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize + NoPaddingBytes,
source§fn eq(&self, other: &SecureArray<T, LENGTH>) -> bool
fn eq(&self, other: &SecureArray<T, LENGTH>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<T, const LENGTH: usize> TryFrom<Vec<T>> for SecureArray<T, LENGTH>where
T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> TryFrom<Vec<T>> for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize,
impl<T, const LENGTH: usize> Eq for SecureArray<T, LENGTH>where T: Sized + Copy + Zeroize + NoPaddingBytes,
Auto Trait Implementations§
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