pub struct Dynamic<T: ?Sized>(pub Box<T>);Expand description
A zero-cost, heap-allocated wrapper for sensitive data.
Dynamic<T> stores its value on the heap via Box<T>. It behaves like T
thanks to Deref/DerefMut, but redacts itself in debug output and requires
explicit access to the inner value.
Use this for dynamic-sized secrets like passwords or variable-length keys.
§Examples
use secure_gate::Dynamic;
let secret: Dynamic<Vec<u8>> = vec![1, 2, 3].into();
assert_eq!(secret.expose_secret(), &[1, 2, 3]);Tuple Fields§
§0: Box<T>Implementations§
Source§impl<T: ?Sized> Dynamic<T>
impl<T: ?Sized> Dynamic<T>
Source§impl<T: ?Sized> Dynamic<T>
impl<T: ?Sized> Dynamic<T>
Sourcepub fn expose_secret(&self) -> &T
pub fn expose_secret(&self) -> &T
Accesses the secret value immutably.
This is the canonical, explicit way to read the secret.
§Examples
use secure_gate::Dynamic;
let secret: Dynamic<String> = "secret".into();
assert_eq!(secret.expose_secret(), "secret");Sourcepub fn expose_secret_mut(&mut self) -> &mut T
pub fn expose_secret_mut(&mut self) -> &mut T
Accesses the secret value mutably.
Use for in-place modifications.
§Examples
use secure_gate::Dynamic;
let mut secret: Dynamic<String> = "hello".into();
secret.expose_secret_mut().push('!');
assert_eq!(secret.expose_secret(), "hello!");Sourcepub fn into_inner(self) -> Box<T>
pub fn into_inner(self) -> Box<T>
Consumes the wrapper and returns the inner boxed value.
§Examples
use secure_gate::Dynamic;
let secret: Dynamic<String> = "owned".into();
let owned: Box<String> = secret.into_inner();
assert_eq!(&*owned, "owned");Source§impl Dynamic<String>
impl Dynamic<String>
Sourcepub fn finish_mut(&mut self) -> &mut String
pub fn finish_mut(&mut self) -> &mut String
Shrinks the string’s capacity to fit its length and returns a mutable reference.
Use this to eliminate slack memory after mutations.
§Examples
use secure_gate::Dynamic;
let mut secret: Dynamic<String> = String::with_capacity(100).into();
secret.push_str("short");
let s: &mut String = secret.finish_mut();
assert_eq!(s.capacity(), 5);Source§impl Dynamic<Vec<u8>>
impl Dynamic<Vec<u8>>
Sourcepub fn finish_mut(&mut self) -> &mut Vec<u8> ⓘ
pub fn finish_mut(&mut self) -> &mut Vec<u8> ⓘ
Shrinks the vector’s capacity to fit its length and returns a mutable reference.
Use this to eliminate slack memory after mutations.
§Examples
use secure_gate::Dynamic;
let mut secret: Dynamic<Vec<u8>> = Vec::with_capacity(100).into();
secret.extend_from_slice(b"short");
let v: &mut Vec<u8> = secret.finish_mut();
assert_eq!(v.capacity(), 5);Trait Implementations§
Source§impl From<&str> for Dynamic<String>
Convenience conversion from &str to Dynamic<String>.
impl From<&str> for Dynamic<String>
Convenience conversion from &str to Dynamic<String>.
§Examples
use secure_gate::Dynamic;
let secret: Dynamic<String> = "password".into();
assert_eq!(secret.expose_secret(), "password");Source§impl<T: ?Sized + Zeroize> From<Dynamic<T>> for DynamicZeroizing<T>
Available on crate feature zeroize only.
impl<T: ?Sized + Zeroize> From<Dynamic<T>> for DynamicZeroizing<T>
zeroize only.Source§impl<T> From<T> for Dynamic<T>where
T: Sized,
Converts an owned value into a Dynamic.
impl<T> From<T> for Dynamic<T>where
T: Sized,
Converts an owned value into a Dynamic.
§Examples
use secure_gate::Dynamic;
let secret: Dynamic<Vec<u8>> = vec![1, 2, 3].into();
assert_eq!(secret.expose_secret(), &[1, 2, 3]);Source§impl<T: PartialEq + ?Sized> PartialEq for Dynamic<T>
Implements PartialEq for Dynamic where T implements PartialEq.
impl<T: PartialEq + ?Sized> PartialEq for Dynamic<T>
Implements PartialEq for Dynamic
This enables comparison on Dynamic types like Dynamic
Source§impl<T: Zeroize + DefaultIsZeroes> Zeroize for Dynamic<T>
Available on crate feature zeroize only.
impl<T: Zeroize + DefaultIsZeroes> Zeroize for Dynamic<T>
zeroize only.impl<T: Eq + ?Sized> Eq for Dynamic<T>
Implements Eq for Dynamic
impl<T: ?Sized + Zeroize> ZeroizeOnDrop for Dynamic<T>
zeroize only.