Skip to main content

Dynamic

Struct Dynamic 

Source
pub struct Dynamic<T: ?Sized> { /* private fields */ }
Expand description

Re-export of the Dynamic type. Dynamic-sized 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>. The inner field is private, forcing all access through explicit methods.

Security invariants:

  • No Deref or AsRef — prevents silent access.
  • Debug is always redacted.
  • With zeroize, wipes the entire allocation on drop (including spare capacity).

Implementations§

Source§

impl<T: ?Sized> Dynamic<T>

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§

impl Dynamic<String>

This impl block contains no items.

§Ergonomic helpers for common heap types

Source§

impl Dynamic<Vec<u8>>

Source

pub fn from_random(len: usize) -> Self

Fill with fresh random bytes of the specified length using the System RNG.

Panics on RNG failure for fail-fast crypto code. Guarantees secure entropy from system sources.

Source§

impl Dynamic<Vec<u8>>

Source

pub fn try_from_hex(s: &str) -> Result<Self, HexError>

Decode a hex string into a Dynamic secret.

§Example
use secure_gate::{Dynamic, ExposeSecret};
let hex_string = "424344";
let secret = Dynamic::try_from_hex(hex_string).unwrap();
assert_eq!(secret.expose_secret().len(), 3);
Source§

impl Dynamic<Vec<u8>>

Source

pub fn try_from_base64url(s: &str) -> Result<Self, Base64Error>

Decode a base64url string into a Dynamic secret.

§Example
use secure_gate::{Dynamic, ExposeSecret};
let b64_string = "QkNE";
let secret = Dynamic::try_from_base64url(b64_string).unwrap();
assert_eq!(secret.expose_secret().len(), 3);
Source§

impl Dynamic<Vec<u8>>

Source

pub fn try_from_bech32(s: &str) -> Result<Self, Bech32Error>

Decode a bech32 string into a Dynamic secret, discarding the HRP.

§Example
use secure_gate::{Dynamic, ExposeSecret, ToBech32};
let original: Dynamic<Vec<u8>> = Dynamic::new(vec![1, 2, 3, 4]);
let bech32_string = original.with_secret(|s| s.to_bech32("test"));
let decoded = Dynamic::try_from_bech32(&bech32_string).unwrap();
// HRP "test" is discarded, bytes are stored
Source§

impl Dynamic<Vec<u8>>

Source

pub fn try_from_bech32m(s: &str) -> Result<Self, Bech32Error>

Decode a bech32m string into a Dynamic secret, discarding the HRP.

§Example
use secure_gate::Dynamic;
// Note: Bech32m strings must be valid Bech32m format
let bech32m_string = "abc1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw";
let secret = Dynamic::try_from_bech32m(bech32m_string);
// Returns Result<Dynamic<Vec<u8>>, Bech32Error>
Source§

impl Dynamic<String>

Source

pub fn ct_eq(&self, other: &Self) -> bool

Constant-time equality comparison.

Compares the byte contents of two instances in constant time to prevent timing attacks.

Source§

impl Dynamic<Vec<u8>>

Source

pub fn ct_eq(&self, other: &Self) -> bool

Constant-time equality comparison.

Compares the byte contents of two instances in constant time to prevent timing attacks.

Trait Implementations§

Source§

impl<T: CloneableSecret> Clone for Dynamic<T>

Available on crate feature cloneable 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> ConstantTimeEq for Dynamic<T>
where T: ConstantTimeEq + ?Sized,

Available on crate feature ct-eq only.
Source§

fn ct_eq(&self, other: &Self) -> bool

Compare two values in constant time. Read more
Source§

impl<T> ConstantTimeEqExt for Dynamic<T>
where T: AsRef<[u8]> + ConstantTimeEq + ?Sized,

Available on crate feature ct-eq-hash only.
Source§

fn len(&self) -> usize

Get the length of the secret data in bytes. Read more
Source§

fn ct_eq_hash(&self, other: &Self) -> bool

Force BLAKE3 digest comparison (constant-time on 32-byte output). Read more
Source§

fn ct_eq_auto(&self, other: &Self, threshold_bytes: Option<usize>) -> bool

Recommended hybrid constant-time equality check. 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<'de> Deserialize<'de> for Dynamic<String>

Available on crate feature serde-deserialize only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de> Deserialize<'de> for Dynamic<Vec<u8>>

Available on crate feature serde-deserialize only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl ExposeSecret for Dynamic<String>

Source§

type Inner = String

The inner secret type being exposed. Read more
Source§

fn with_secret<F, R>(&self, f: F) -> R
where F: FnOnce(&String) -> R,

Provide scoped read-only access to the secret. Read more
Source§

fn expose_secret(&self) -> &String

Expose the secret for read-only access. Read more
Source§

fn len(&self) -> usize

Returns the length of the secret.
Source§

fn is_empty(&self) -> bool

Returns true if the secret is empty.
Source§

impl<T> ExposeSecret for Dynamic<Vec<T>>

Source§

type Inner = Vec<T>

The inner secret type being exposed. Read more
Source§

fn with_secret<F, R>(&self, f: F) -> R
where F: FnOnce(&Vec<T>) -> R,

Provide scoped read-only access to the secret. Read more
Source§

fn expose_secret(&self) -> &Vec<T>

Expose the secret for read-only access. Read more
Source§

fn len(&self) -> usize

Returns the length of the secret.
Source§

fn is_empty(&self) -> bool

Returns true if the secret is empty.
Source§

impl ExposeSecretMut for Dynamic<String>

Source§

fn with_secret_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut String) -> R,

Provide scoped mutable access to the secret. Read more
Source§

fn expose_secret_mut(&mut self) -> &mut String

Expose the secret for mutable access. Read more
Source§

impl<T> ExposeSecretMut for Dynamic<Vec<T>>

Source§

fn with_secret_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Vec<T>) -> R,

Provide scoped mutable access to the secret. Read more
Source§

fn expose_secret_mut(&mut self) -> &mut Vec<T>

Expose the secret for mutable access. Read more
Source§

impl From<&[u8]> for Dynamic<Vec<u8>>

Source§

fn from(slice: &[u8]) -> Self

Wrap a byte slice in a Dynamic Vec<u8>.

Source§

impl From<&str> for Dynamic<String>

Source§

fn from(input: &str) -> Self

Wrap a string slice in a Dynamic String.

Source§

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

Source§

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

Wrap a boxed value in a Dynamic secret.

Source§

impl<T: 'static> From<T> for Dynamic<T>

Source§

fn from(value: T) -> Self

Wrap a value in a Dynamic secret by boxing it.

Source§

impl<T> Serialize for Dynamic<T>

Available on crate feature serde-serialize only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
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.

Zeroize on drop integration

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,