pub struct SecretVec { /* private fields */ }Expand description
Variable-size secret vector that wipes storage it owns
This type provides:
- Automatic zeroization on drop
- Secure cloning that preserves security properties
- Dynamic sizing with secure memory management
Implementations§
Source§impl SecretVec
impl SecretVec
Sourcepub fn new(data: Vec<u8>) -> SecretVec
pub fn new(data: Vec<u8>) -> SecretVec
Create a new secret vector with the given data.
The current allocation and its spare capacity become protected by this
type. Allocations the caller freed before passing this Vec cannot be
recovered or retroactively wiped.
Sourcepub fn from_slice(slice: &[u8]) -> SecretVec
pub fn from_slice(slice: &[u8]) -> SecretVec
Create a secret vector from a slice
Sourcepub fn with_capacity(capacity: usize) -> SecretVec
pub fn with_capacity(capacity: usize) -> SecretVec
Create a secret vector with the specified capacity
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Get a mutable reference to the inner data
Sourcepub fn extend_from_slice(&mut self, slice: &[u8])
pub fn extend_from_slice(&mut self, slice: &[u8])
Extend the vector with additional data
Sourcepub fn push(&mut self, value: u8)
pub fn push(&mut self, value: u8)
Append one byte, securely replacing the allocation when it is full.
Sourcepub fn pop(&mut self) -> Option<u8>
pub fn pop(&mut self) -> Option<u8>
Remove and return the last byte, wiping its allocation slot first.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve room for at least additional more bytes.
Unlike Vec::reserve, this never asks the allocator to resize the live
secret allocation. It copies into a new allocation and wipes the old
allocation before releasing it.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Reduce capacity to the current length while wiping the old allocation.
Trait Implementations§
Source§impl SecureZeroingType for SecretVec
Available on crate feature alloc only.
impl SecureZeroingType for SecretVec
alloc only.Auto Trait Implementations§
impl Freeze for SecretVec
impl RefUnwindSafe for SecretVec
impl Send for SecretVec
impl Sync for SecretVec
impl Unpin for SecretVec
impl UnsafeUnpin for SecretVec
impl UnwindSafe for SecretVec
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConstantTimeEquals for T
impl<T> ConstantTimeEquals for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)