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>) -> Self
pub fn new(data: Vec<u8>) -> Self
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]) -> Self
pub fn from_slice(slice: &[u8]) -> Self
Create a secret vector from a slice
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
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.