Skip to main content

SecretBuf

Struct SecretBuf 

Source
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

Source

pub fn new(data: Vec<u8>) -> Self

Wrap an existing allocation. Takes ownership; the buffer will be securely zeroed when the SecretBuf is dropped.

Source

pub fn with_len(len: usize) -> Self

Allocate a zero-initialised buffer of len bytes.

Source

pub fn from_slice(data: &[u8]) -> Self

Copy data into a new secure buffer.

Source

pub fn len(&self) -> usize

Number of bytes in the buffer.

Source

pub fn is_empty(&self) -> bool

true if the buffer holds no bytes.

Source

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§

Source§

impl AsRef<[u8]> for SecretBuf

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Drop for SecretBuf

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for SecretBuf

Source§

impl Sync for SecretBuf

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.