pub struct SecretVec(/* private fields */);Expand description
A vector that zeroizes its contents on drop.
Use this type for storing sensitive data like keys, passwords, or plaintext that should not remain in memory after use.
§Example
use crabgraph::secrets::SecretVec;
let mut secret = SecretVec::new(vec![1, 2, 3, 4]);
// Use secret...
drop(secret); // Memory is automatically zeroizedImplementations§
Source§impl SecretVec
impl SecretVec
Sourcepub fn new(data: Vec<u8>) -> Self
pub fn new(data: Vec<u8>) -> Self
Creates a new SecretVec from a byte vector.
§Example
use crabgraph::secrets::SecretVec;
let secret = SecretVec::new(vec![1, 2, 3]);Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new SecretVec with the specified capacity.
§Example
use crabgraph::secrets::SecretVec;
let mut secret = SecretVec::with_capacity(32);Sourcepub fn zero(len: usize) -> Self
pub fn zero(len: usize) -> Self
Creates a new SecretVec filled with zeros.
§Example
use crabgraph::secrets::SecretVec;
let secret = SecretVec::zero(32);
assert_eq!(secret.len(), 32);Sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Returns a reference to the secret data.
§Security Note
Be careful not to copy or clone the returned slice, as that would create unprotected copies in memory.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the secret data.
§Security Note
Any modifications should be careful not to leak the old data.
Sourcepub fn into_inner(self) -> Vec<u8> ⓘ
pub fn into_inner(self) -> Vec<u8> ⓘ
Consumes the SecretVec and returns the inner Vec<u8>.
§Security Warning
The returned Vec<u8> is NOT automatically zeroized. Use this only
when you need to pass ownership to another zeroizing container.
Sourcepub fn extend_from_slice(&mut self, data: &[u8])
pub fn extend_from_slice(&mut self, data: &[u8])
Extends the secret with additional data.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SecretVec
impl RefUnwindSafe for SecretVec
impl Send for SecretVec
impl Sync for SecretVec
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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)