pub struct SecretArray<const N: usize>(/* private fields */);Expand description
An owned, zeroizing wrapper around a fixed-size [u8; N] stack array.
Intended for fixed-size key material such as X25519 private seeds, AEAD
keys, and shared secrets ([u8; 32]). The stack bytes are overwritten with
zeros on Drop. Debug is redacted. Clone
produces an independent value that also zeroizes on its own drop.
Implementations§
Source§impl<const N: usize> SecretArray<N>
impl<const N: usize> SecretArray<N>
Sourcepub const fn expose_secret(&self) -> &[u8] ⓘ
pub const fn expose_secret(&self) -> &[u8] ⓘ
Borrows the secret as a &[u8] view.
All uses of this function should be carefully reviewed to ensure the value is not printed or copied to a non-Secret-wrapped storage. The borrow does not change ownership and the secret is still zeroed on drop.
Sourcepub const fn into_inner(self) -> [u8; N]
pub const fn into_inner(self) -> [u8; N]
Consumes the wrapper and returns the plain owned [u8; N].
This is the ownership-handoff path for when key material must leave the
library boundary. The moved-out value is not zeroized (that is the
point of handoff); the caller then owns leak prevention. No wrapped copy
remains, because self is consumed by value.
Note: [u8; N] is Copy, so this returns a bit-for-bit copy and the
(now-moved) self is dropped — its storage is the same bytes the copy
carries, so this does not zero the returned value.
Trait Implementations§
Source§impl<const N: usize> Clone for SecretArray<N>
impl<const N: usize> Clone for SecretArray<N>
Source§fn clone(&self) -> SecretArray<N>
fn clone(&self) -> SecretArray<N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more