pub struct SecretBox<S: Zeroize + ?Sized> { /* private fields */ }Expand description
Heap-allocated secret wrapper — mirrors secrecy::SecretBox.
Stores the secret in a Box<S>, zeroizes on drop, and only exposes the inner
value through ExposeSecret /
ExposeSecretMut. Debug always prints [REDACTED].
§Migration to native secure-gate
For sized types, convert to Dynamic<S> using the provided
From impl:
use secure_gate::compat::v10::SecretBox;
use secure_gate::Dynamic;
let compat: SecretBox<String> = SecretBox::init_with(|| String::from("hunter2"));
let native: Dynamic<String> = compat.into();Implementations§
Source§impl<S: Zeroize + Default> SecretBox<S>
impl<S: Zeroize + Default> SecretBox<S>
Sourcepub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self
pub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self
Creates a SecretBox by initializing the default value in-place via a mutable closure.
Trait Implementations§
Source§impl<S: CloneableSecret> Clone for SecretBox<S>
impl<S: CloneableSecret> Clone for SecretBox<S>
Source§impl<'de, T> Deserialize<'de> for SecretBox<T>
Available on crate feature serde-deserialize only.
impl<'de, T> Deserialize<'de> for SecretBox<T>
serde-deserialize only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<S: Zeroize + ?Sized> ExposeSecret<S> for SecretBox<S>
impl<S: Zeroize + ?Sized> ExposeSecret<S> for SecretBox<S>
Source§fn expose_secret(&self) -> &S
fn expose_secret(&self) -> &S
Source§impl<S: Zeroize + ?Sized> ExposeSecretMut<S> for SecretBox<S>
impl<S: Zeroize + ?Sized> ExposeSecretMut<S> for SecretBox<S>
Source§fn expose_secret_mut(&mut self) -> &mut S
fn expose_secret_mut(&mut self) -> &mut S
Source§impl From<Dynamic<String>> for SecretBox<String>
Converts a Dynamic<String> back into a SecretBox<String>.
impl From<Dynamic<String>> for SecretBox<String>
Converts a Dynamic<String> back into a SecretBox<String>.
Clones the inner String. Both the source and the new wrapper are zeroized on drop.
Source§impl<S: Clone + Zeroize + 'static> From<Dynamic<Vec<S>>> for SecretBox<Vec<S>>
Converts a Dynamic<Vec<S>> back into a SecretBox<Vec<S>>.
impl<S: Clone + Zeroize + 'static> From<Dynamic<Vec<S>>> for SecretBox<Vec<S>>
Converts a Dynamic<Vec<S>> back into a SecretBox<Vec<S>>.
Clones the inner Vec. Both ends are zeroized on drop.
Source§impl<S: Clone + Zeroize + 'static> From<SecretBox<S>> for Dynamic<S>
Converts a SecretBox<S> into a Dynamic<S> (primary migration path).
impl<S: Clone + Zeroize + 'static> From<SecretBox<S>> for Dynamic<S>
Converts a SecretBox<S> into a Dynamic<S> (primary migration path).
Requires S: Clone because the inner Box<S> cannot be moved out of SecretBox
without unsafe code (SecretBox has a Drop impl). The clone is immediately
wrapped in Dynamic and the original is zeroized on drop.
For zero-copy migration, construct Dynamic<S> directly instead.
Source§impl From<SecretBox<str>> for Dynamic<String>
Converts a SecretString (= SecretBox<str>) into a Dynamic<String>.
impl From<SecretBox<str>> for Dynamic<String>
Converts a SecretString (= SecretBox<str>) into a Dynamic<String>.
Clones the inner str into a new String. Both ends are zeroized on drop.