pub struct Dynamic<T: ?Sized>(/* private fields */);Expand description
Heap-allocated secure secret wrapper.
This is a thin wrapper around Box<T> with enforced explicit exposure.
Suitable for dynamic-sized secrets like String or Vec<u8>.
Security invariants:
- No
DereforAsRef— prevents silent access. Debugis always redacted.- With
zeroize, wipes the entire allocation on drop (including spare capacity).
§Examples
Basic usage:
use secure_gate::Dynamic;
let secret: Dynamic<String> = "hunter2".into();
assert_eq!(secret.expose_secret(), "hunter2");Mutable access:
use secure_gate::Dynamic;
let mut secret = Dynamic::<String>::new("pass".to_string());
secret.expose_secret_mut().push('!');
assert_eq!(secret.expose_secret(), "pass!");With zeroize (automatic wipe):
use secure_gate::Dynamic;
let secret = Dynamic::<Vec<u8>>::new(vec![1u8; 32]);
drop(secret); // heap wiped automaticallyImplementations§
Source§impl<T: ?Sized> Dynamic<T>
impl<T: ?Sized> Dynamic<T>
Sourcepub fn new_boxed(value: Box<T>) -> Self
pub fn new_boxed(value: Box<T>) -> Self
Wrap an already-boxed value.
Zero-cost — just wraps the Box.
Sourcepub const fn expose_secret(&self) -> &T
pub const fn expose_secret(&self) -> &T
Expose the inner value for read-only access.
This is the only way to read the secret — loud and auditable.
Sourcepub fn expose_secret_mut(&mut self) -> &mut T
pub fn expose_secret_mut(&mut self) -> &mut T
Expose the inner value for mutable access.
This is the only way to mutate the secret — loud and auditable.
Sourcepub fn no_clone(self) -> DynamicNoClone<T>
pub fn no_clone(self) -> DynamicNoClone<T>
Convert to a non-cloneable variant.
Prevents accidental cloning of the secret.
§Example
use secure_gate::{Dynamic, DynamicNoClone};
let secret = Dynamic::<String>::new("no copy".to_string());
let no_clone: DynamicNoClone<String> = secret.no_clone();
assert_eq!(no_clone.expose_secret(), "no copy");Source§impl<T: ?Sized + Zeroize> Dynamic<T>
impl<T: ?Sized + Zeroize> Dynamic<T>
Sourcepub fn zeroize_now(&mut self)
pub fn zeroize_now(&mut self)
Explicitly zeroize the secret immediately.
This is useful when you want to wipe memory before the value goes out of scope, or when you want to make the zeroization intent explicit in the code.
§Example
use secure_gate::Dynamic;
let mut password = Dynamic::<String>::new("secret".to_string());
// ... use password ...
password.zeroize_now(); // Explicit wipe - makes intent clearTrait Implementations§
impl<T: ?Sized + Zeroize> ZeroizeOnDrop for Dynamic<T>
zeroize only.