pub struct SealedDynamic<T: SealedPayload> { /* private fields */ }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>
impl<T: SealedPayload> SealedDynamic<T>
Sourcepub fn seal(secret: Dynamic<T>, prekey: &Arc<Prekey>) -> Self
pub fn seal(secret: Dynamic<T>, prekey: &Arc<Prekey>) -> Self
Seals secret under prekey. The plain wrapper is consumed and wiped on drop.
Sourcepub fn with_secret<F, R>(&self, f: F) -> R
pub fn with_secret<F, R>(&self, f: F) -> R
Decrypts into a temporary for the length of f, then wipes the temporary.
Sourcepub fn with_secret_mut<F, R>(&mut self, f: F) -> R
pub fn with_secret_mut<F, R>(&mut self, f: F) -> 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.
Sourcepub fn unseal(self) -> Dynamic<T>
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.
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.
impl<T: SealedPayload> ConstantTimeEq for SealedDynamic<T>
ct-eq only.Constant-time equality: opens both sides and compares the plaintext with subtle.
Unequal lengths compare unequal without opening either side.
Source§impl<T: SealedPayload> Debug for SealedDynamic<T>
Always prints [REDACTED]: no salt, no tag, no length.
impl<T: SealedPayload> Debug for SealedDynamic<T>
Always prints [REDACTED]: no salt, no tag, no length.