pub struct SecureVec<T>{ /* 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::Debugandfmt::Display
- Automatic mlockto 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.
Be careful with SecureBytes::from: if you have a borrowed string, it will be copied.
Use SecureBytes::new if you have a Vec<u8>.
Implementations§
Source§impl<T> SecureVec<T>
 
impl<T> SecureVec<T>
pub fn new(cont: Vec<T>) -> Self
Sourcepub fn unsecure_mut(&mut self) -> &mut [T]
 
pub fn unsecure_mut(&mut self) -> &mut [T]
Mutably borrow the contents of the string.
Sourcepub fn resize(&mut self, new_len: usize, value: T)
 
pub fn resize(&mut self, new_len: usize, value: T)
Resizes the SecureVec in-place so that len is equal to new_len.
If new_len is smaller the inner vector is truncated.
If new_len is larger the inner vector will grow, placing value in all new cells.
This ensures that the new memory region is secured if reallocation occurs.
Similar to Vec::resize
Trait Implementations§
Source§impl<T> BorrowMut<[T]> for SecureVec<T>
 
impl<T> BorrowMut<[T]> for SecureVec<T>
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 SecureVec<T>
 
impl<T> Ord for SecureVec<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 SecureVec<T>
 
impl<T> PartialOrd for SecureVec<T>
impl<T> Eq for SecureVec<T>
impl<T> StructuralPartialEq for SecureVec<T>
Auto Trait Implementations§
impl<T> Freeze for SecureVec<T>
impl<T> RefUnwindSafe for SecureVec<T>where
    T: RefUnwindSafe,
impl<T> Send for SecureVec<T>where
    T: Send,
impl<T> Sync for SecureVec<T>where
    T: Sync,
impl<T> Unpin for SecureVec<T>where
    T: Unpin,
impl<T> UnwindSafe for SecureVec<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