pub struct SecretBuf { /* private fields */ }Expand description
A heap buffer that is securely zeroed via OPENSSL_cleanse on drop.
Use to hold key material, passwords, and other sensitive byte sequences.
The zeroing is performed by OpenSSL’s OPENSSL_cleanse, which is the
FIPS-approved memory-clearing function and is not eliminated by the
compiler’s dead-store optimiser.
§Example
ⓘ
use native_ossl::util::SecretBuf;
let mut key = SecretBuf::with_len(32);
native_ossl::rand::Rand::fill(key.as_mut_slice()).unwrap();
// key bytes are securely erased when `key` is dropped.Implementations§
Source§impl SecretBuf
impl SecretBuf
Sourcepub fn new(data: Vec<u8>) -> Self
pub fn new(data: Vec<u8>) -> Self
Wrap an existing allocation. Takes ownership; the buffer will be
securely zeroed when the SecretBuf is dropped.
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Copy data into a new secure buffer.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Expose the buffer as a mutable byte slice.
Useful for writing derived key material directly into the buffer.
Trait Implementations§
impl Send for SecretBuf
impl Sync for SecretBuf
Auto Trait Implementations§
impl Freeze for SecretBuf
impl RefUnwindSafe for SecretBuf
impl Unpin for SecretBuf
impl UnsafeUnpin for SecretBuf
impl UnwindSafe for SecretBuf
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