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 into_inner(self) -> Box<T>
pub fn into_inner(self) -> Box<T>
Consume the wrapper and return the inner Box<T>.
Note: If zeroize is enabled, prefer dropping the Dynamic to ensure wiping.
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");Trait Implementations§
impl<T: ?Sized + Zeroize> ZeroizeOnDrop for Dynamic<T>
Available on crate feature
zeroize only.Auto Trait Implementations§
impl<T> Freeze for Dynamic<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Dynamic<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for Dynamic<T>
impl<T> Sync for Dynamic<T>
impl<T> Unpin for Dynamic<T>where
T: ?Sized,
impl<T> UnwindSafe for Dynamic<T>where
T: UnwindSafe + ?Sized,
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
Mutably borrows from an owned value. Read more