Skip to main content

SensitiveBytes

Struct SensitiveBytes 

Source
pub struct SensitiveBytes<const N: usize, O> { /* private fields */ }
Expand description

N is the byte length and O is a chosen zero-sized type that lets the type system track where the bytes came from (BIP39 seed, dice entropy, AES key, decrypted KEF payload, etc…).

§Example

use kdk_zeroize::SensitiveBytes;

// A caller-chosen marker type.
pub enum AesKey {}

type AesKey256 = SensitiveBytes<32, AesKey>;


let key = AesKey256::new([0u8; 32]);

Implementations§

Source§

impl<const N: usize, O> SensitiveBytes<N, O>

Source

pub const fn new(bytes: [u8; N]) -> Self

Wrap a [u8; N] as origin-tagged sensitive bytes.

Source

pub fn as_slice(&self) -> &[u8]

Same bytes as Sensitive::expose_secret; the looser &[u8] return is fine for non-cryptographic reads (e.g. equality checks in tests).

Trait Implementations§

Source§

impl<const N: usize, O> Debug for SensitiveBytes<N, O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, O> Display for SensitiveBytes<N, O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, O> Drop for SensitiveBytes<N, O>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const N: usize, O> Sensitive for SensitiveBytes<N, O>

Source§

type Inner = [u8; N]

The type whose bytes are the secret material.
Source§

fn expose_secret(&self) -> &[u8; N]

Explicit-secret-access getter. Mirrors the inherent expose_secret every sensitive type provides.
Source§

impl<const N: usize, O> SensitiveMut for SensitiveBytes<N, O>

Source§

fn expose_secret_mut(&mut self) -> &mut [u8; N]

Mutable explicit-secret-access getter.

Auto Trait Implementations§

§

impl<const N: usize, O> Freeze for SensitiveBytes<N, O>

§

impl<const N: usize, O> RefUnwindSafe for SensitiveBytes<N, O>
where O: RefUnwindSafe,

§

impl<const N: usize, O> Send for SensitiveBytes<N, O>
where O: Send,

§

impl<const N: usize, O> Sync for SensitiveBytes<N, O>
where O: Sync,

§

impl<const N: usize, O> Unpin for SensitiveBytes<N, O>
where O: Unpin,

§

impl<const N: usize, O> UnsafeUnpin for SensitiveBytes<N, O>

§

impl<const N: usize, O> UnwindSafe for SensitiveBytes<N, O>
where O: UnwindSafe,

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.