pub struct SecretVec { /* private fields */ }Expand description
Variable-length byte sequence stored in guarded, zeroizing memory.
Secret bytes are deliberately unavailable through Deref or indexing. Use
a callback-scoped read method and avoid retaining ordinary-memory copies.
Implementations§
Source§impl SecureVec
impl SecureVec
Sourcepub fn try_from_vec(bytes: Vec<u8>) -> Result<SecureVec, Error>
pub fn try_from_vec(bytes: Vec<u8>) -> Result<SecureVec, Error>
Moves bytes into secure memory and zeroizes the input vector.
Sourcepub fn try_from_slice(bytes: &[u8]) -> Result<SecureVec, Error>
pub fn try_from_slice(bytes: &[u8]) -> Result<SecureVec, Error>
Copies a byte slice into secure memory.
Sourcepub fn try_clone(&self) -> Result<SecureVec, Error>
pub fn try_clone(&self) -> Result<SecureVec, Error>
Creates an independent secure copy without exposing plaintext bytes.
Sourcepub fn with_bytes<R>(&self, f: impl FnOnce(&[u8]) -> R) -> Result<R, Error>
pub fn with_bytes<R>(&self, f: impl FnOnce(&[u8]) -> R) -> Result<R, Error>
Exposes the bytes only for the duration of f.
Sourcepub fn with_bytes_in<R>(
&self,
access: &SecureReadAccess<'_>,
f: impl FnOnce(&[u8]) -> R,
) -> Result<R, Error>
pub fn with_bytes_in<R>( &self, access: &SecureReadAccess<'_>, f: impl FnOnce(&[u8]) -> R, ) -> Result<R, Error>
Exposes bytes using an existing secure read scope.
Sourcepub fn try_push(&mut self, byte: u8) -> Result<(), Error>
pub fn try_push(&mut self, byte: u8) -> Result<(), Error>
Appends one byte, growing the secure allocation when required.
Sourcepub fn try_extend_from_slice(&mut self, bytes: &[u8]) -> Result<(), Error>
pub fn try_extend_from_slice(&mut self, bytes: &[u8]) -> Result<(), Error>
Appends ordinary bytes to this secure allocation.
Sourcepub fn try_extend_from_secure(
&mut self,
source: &SecureVec,
) -> Result<(), Error>
pub fn try_extend_from_secure( &mut self, source: &SecureVec, ) -> Result<(), Error>
Appends all bytes from another secure vector without normal-heap copies.
Sourcepub fn try_extend_secure_range(
&mut self,
source: &SecureVec,
offset: usize,
len: usize,
) -> Result<(), Error>
pub fn try_extend_secure_range( &mut self, source: &SecureVec, offset: usize, len: usize, ) -> Result<(), Error>
Appends a validated range from another secure vector.
Returns Error::CapacityOverflow if the range is outside source.
Sourcepub fn try_clone_range(
&self,
offset: usize,
len: usize,
) -> Result<SecureVec, Error>
pub fn try_clone_range( &self, offset: usize, len: usize, ) -> Result<SecureVec, Error>
Creates a secure copy of a validated byte range.
Sourcepub fn resize_zeroed(&mut self, len: usize) -> Result<(), Error>
pub fn resize_zeroed(&mut self, len: usize) -> Result<(), Error>
Changes the logical length, zero-filling growth and wiping truncation.
Sourcepub fn truncate(&mut self, len: usize) -> Result<(), Error>
pub fn truncate(&mut self, len: usize) -> Result<(), Error>
Shortens the vector and wipes the removed range.
Sourcepub fn with_mut_bytes<R>(
&mut self,
f: impl FnOnce(&mut [u8]) -> R,
) -> Result<R, Error>
pub fn with_mut_bytes<R>( &mut self, f: impl FnOnce(&mut [u8]) -> R, ) -> Result<R, Error>
Grants mutable access for the duration of f and restores protection.
Mutation fails with Error::ReadAccessActive during any read scope.