Skip to main content

SealedDynamic

Struct SealedDynamic 

Source
pub struct SealedDynamic<T: SealedPayload> { /* private fields */ }
Available on crate feature sealed only.
Expand description

A variable-length secret (Vec<u8> or String) held encrypted in RAM while idle, opened for one closure call at a time. The sealed counterpart of Dynamic. Requires the sealed feature.

The ciphertext lives in an exact-size Box<[u8]>. Each access decrypts into an exact-capacity Dynamic that its Drop wipes. As with SealedFixed there is no expose_secret and no RevealSecret impl.

use secure_gate::{Dynamic, Prekey, SealedDynamic};

let prekey = Prekey::new();
let mut pw = SealedDynamic::seal(Dynamic::new(String::from("hunter2")), &prekey);
pw.with_secret(|s: &String| assert_eq!(s, "hunter2"));
pw.with_secret_mut(|s: &mut str| s.make_ascii_uppercase());
pw.with_secret(|s| assert_eq!(s, "HUNTER2"));

§Panics

Every access panics if the sealed bytes fail to authenticate. The temporary is wiped and the stack below the call scrubbed before the panic continues.

Implementations§

Source§

impl<T: SealedPayload> SealedDynamic<T>

Source

pub fn seal(secret: Dynamic<T>, prekey: &Arc<Prekey>) -> Self

Seals secret under prekey. The plain wrapper is consumed and wiped on drop.

Source

pub fn with_secret<F, R>(&self, f: F) -> R
where F: FnOnce(&T) -> R,

Decrypts into a temporary for the length of f, then wipes the temporary.

Source

pub fn with_secret_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut T::Mut) -> R,

Decrypts into a temporary, lets f change it in place, then seals the result under a fresh salt and wipes the temporary.

f gets &mut [u8] or &mut str, never &mut Vec or &mut String: the length is fixed, so the buffer can never reallocate and abandon an unwiped copy of the plaintext. To change the length, unseal, edit, and seal again.

If f panics, the temporary is still wiped, the stack scrubbed, and the sealed value left as it was.

Source

pub fn unseal(self) -> Dynamic<T>

Opens the secret back into a plain Dynamic. Protection from sealing ends here; the returned wrapper still wipes on drop.

Source

pub fn len(&self) -> usize

The secret’s length in bytes. Length can itself be sensitive for passwords; it is not printed by Debug.

Source

pub fn is_empty(&self) -> bool

true if the secret is empty.

Trait Implementations§

Source§

impl<T: SealedPayload> ConstantTimeEq for SealedDynamic<T>

Available on crate feature ct-eq only.

Constant-time equality: opens both sides and compares the plaintext with subtle. Unequal lengths compare unequal without opening either side.

Source§

fn ct_eq(&self, other: &Self) -> bool

Performs equality comparison in constant time. Read more
Source§

impl<T: SealedPayload> Debug for SealedDynamic<T>

Always prints [REDACTED]: no salt, no tag, no length.

Source§

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

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

impl<T: SealedPayload> RevealScoped for SealedDynamic<T>

Source§

type Inner = T

The secret’s type as the closure sees it.
Source§

fn with_secret<F, R>(&self, f: F) -> R
where F: FnOnce(&T) -> R,

Calls f with a reference to the secret that cannot outlive the call.

Auto Trait Implementations§

§

impl<T> Freeze for SealedDynamic<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for SealedDynamic<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for SealedDynamic<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for SealedDynamic<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for SealedDynamic<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for SealedDynamic<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for SealedDynamic<T>
where PhantomData<fn() -> T>: 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.