Dynamic

Struct Dynamic 

Source
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 Deref or AsRef — prevents silent access.
  • Debug is 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 automatically

Implementations§

Source§

impl<T: ?Sized> Dynamic<T>

Source

pub fn new_boxed(value: Box<T>) -> Self

Wrap an already-boxed value.

Zero-cost — just wraps the Box.

Source

pub fn new<U>(value: U) -> Self
where U: Into<Box<T>>,

Wrap a value by boxing it.

Uses Into<Box<T>> for flexibility.

Source

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.

Source

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.

Source

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>

Source

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 clear
Source§

impl Dynamic<String>

Source

pub const fn len(&self) -> usize

Source

pub const fn is_empty(&self) -> bool

Source§

impl<T> Dynamic<Vec<T>>

Source

pub const fn len(&self) -> usize

Source

pub const fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<T: Clone + Zeroize> Clone for Dynamic<T>

Available on crate feature zeroize only.
Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized> Debug for Dynamic<T>

Source§

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

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

impl From<&str> for Dynamic<String>

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized> From<Box<T>> for Dynamic<T>

Source§

fn from(boxed: Box<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Dynamic<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized + Zeroize> Zeroize for Dynamic<T>

Available on crate feature zeroize only.
Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

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>
where T: Send + ?Sized,

§

impl<T> Sync for Dynamic<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for Dynamic<T>
where T: ?Sized,

§

impl<T> UnwindSafe for Dynamic<T>
where T: UnwindSafe + ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.