pub struct Redacted<T: Zeroize = String>(/* private fields */);Expand description
A secret value whose Debug/Display output is always ***, and whose backing memory
is zeroized when it is dropped.
Wrap any credential that must never reach a log line, a panic message, or a future
#[derive(Debug)] added to a struct embedding it. T defaults to String, the shape
every current call site needs; a caller that needs a different backing type must supply
one that implements [Zeroize] (e.g. secret bytes as Vec<u8>).
§Examples
use deps_core::secret::Redacted;
let token = Redacted::new("super-secret-value".to_string());
assert_eq!(token.expose_secret(), "super-secret-value");
assert_eq!(format!("{token:?}"), "Redacted(***)");
assert_eq!(format!("{token}"), "***");Implementations§
Source§impl<T: Zeroize> Redacted<T>
impl<T: Zeroize> Redacted<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Wraps value. The only way to recover it is Self::expose_secret (for T: AsRef<str>).
Source§impl<T: Zeroize + AsRef<str>> Redacted<T>
impl<T: Zeroize + AsRef<str>> Redacted<T>
Sourcepub fn expose_secret(&self) -> &str
pub fn expose_secret(&self) -> &str
The raw secret value. Never pass this to anything but the one call site that needs
it (e.g. attaching a header value to a request) — never to a log, error message, or
anything Debug/Display-formatted downstream.
Named expose_secret() rather than as_str() deliberately, mirroring the secrecy
crate’s ExposeSecret::expose_secret() convention: a name shared with hundreds of
ordinary string-conversion methods across the workspace cannot be grepped for in
isolation, while a distinctive name lets a reviewer or a future automated lint find
every place a secret’s plaintext crosses its wrapper boundary with a single search.
Trait Implementations§
impl<T: Zeroize + Eq> Eq for Redacted<T>
Source§impl<T: Zeroize + Hash> Hash for Redacted<T>
Hashes the wrapped value, not the redaction wrapper — so Redacted<T> can be used as (or
inside) a hash-map/set key exactly when T itself could be. Opt-in via T: Hash, same
shape as the PartialEq/Eq impls above: a caller that needs this must ask for it by
bounding on Hash, so embedding a secret in a hash key stays a deliberate choice at each
call site rather than something a blanket impl would make automatic.
impl<T: Zeroize + Hash> Hash for Redacted<T>
Hashes the wrapped value, not the redaction wrapper — so Redacted<T> can be used as (or
inside) a hash-map/set key exactly when T itself could be. Opt-in via T: Hash, same
shape as the PartialEq/Eq impls above: a caller that needs this must ask for it by
bounding on Hash, so embedding a secret in a hash key stays a deliberate choice at each
call site rather than something a blanket impl would make automatic.
impl<T: Zeroize> ZeroizeOnDrop for Redacted<T>
Marker confirming Redacted<T> zeroizes its backing memory on drop — the actual
zeroing is performed by the wrapped [Zeroizing<T>] field’s own Drop impl.
Auto Trait Implementations§
impl<T> Freeze for Redacted<T>where
T: Freeze,
impl<T> RefUnwindSafe for Redacted<T>where
T: RefUnwindSafe,
impl<T> Send for Redacted<T>where
T: Send,
impl<T> Sync for Redacted<T>where
T: Sync,
impl<T> Unpin for Redacted<T>where
T: Unpin,
impl<T> UnsafeUnpin for Redacted<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Redacted<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.