pub struct GuardedKey { /* private fields */ }Expand description
Memory-hardened key vault backed by 32 indistinguishable static arrays.
Implementations§
Source§impl GuardedKey
impl GuardedKey
pub const fn empty() -> Self
Sourcepub fn store_from_keys(&self, keys: &Keys, others: &[&GuardedKey])
pub fn store_from_keys(&self, keys: &Keys, others: &[&GuardedKey])
Extract the secret key from a Keys struct, store it in the vault,
and zeroize the intermediate bytes. One-liner replacement for the
repeated extract -> set -> zeroize pattern across login paths.
others is a slice of references to other active GuardedKey instances
for cross-key protection during decoy writes.
Sourcepub fn set(&self, key: [u8; 32], others: &[&GuardedKey])
pub fn set(&self, key: [u8; 32], others: &[&GuardedKey])
Store a key: shielded under its new lane’s prekey, XOR-split into 4 shares scattered across the arrays, with decoy writes to ALL arrays so real writes are indistinguishable.
INVARIANT: pass EVERY other live key (the standing vaults are always included). Decoys keep off only the slots and prekey rows of the keys named here.
Sourcepub fn read<R>(&self, f: impl FnOnce(Option<&[u8; 32]>) -> R) -> R
pub fn read<R>(&self, f: impl FnOnce(Option<&[u8; 32]>) -> R) -> R
Run f on the key, or on None when the vault is empty. The key is rebuilt into one
buffer f borrows, which is wiped when it returns, and then the stack both used is
zeroed: only what f returns or stores outlives the call. Zero writes to the vault.
Sourcepub fn with_key<R>(&self, f: impl FnOnce(&[u8; 32]) -> R) -> Option<R>
pub fn with_key<R>(&self, f: impl FnOnce(&[u8; 32]) -> R) -> Option<R>
Self::read for a vault expected to hold a key: None when it is empty.
Sourcepub fn with_keys<R>(&self, f: impl FnOnce(&Keys) -> R) -> Option<R>
pub fn with_keys<R>(&self, f: impl FnOnce(&Keys) -> R) -> Option<R>
Self::with_key as a keypair, dropped (and wiped) when f returns.
Sourcepub fn clear(&self, others: &[&GuardedKey])
pub fn clear(&self, others: &[&GuardedKey])
Clear the key: retire its prekey and write decoys to all arrays, keeping off every other
live key named in others.
pub fn has_key(&self) -> bool
Sourcepub fn to_keys(&self) -> Option<Keys>
pub fn to_keys(&self) -> Option<Keys>
An owned keypair, for an object that must keep one past the call (a NIP-46 client).
Its moves leave copies nothing wipes, so shipping code marks each use // owned-key:
(vault_audit enforces it); everything else uses Self::with_keys.
Auto Trait Implementations§
impl !Freeze for GuardedKey
impl Forget for GuardedKey
impl Move for GuardedKey
impl RefUnwindSafe for GuardedKey
impl Send for GuardedKey
impl Sync for GuardedKey
impl Unpin for GuardedKey
impl UnsafeUnpin for GuardedKey
impl UnwindSafe for GuardedKey
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more