pub struct Secret(/* private fields */);Expand description
Wrapper for sensitive strings with redacted Debug/Display.
The inner value is wrapped in Zeroizing which overwrites the memory on drop.
Clone is intentionally not derived — secrets must be explicitly duplicated via
Secret::new(existing.expose().to_owned()).
§Clone is not implemented
use zeph_common::secret::Secret;
let s = Secret::new("x");
let _ = s.clone(); // must not compile — Secret intentionally does not implement CloneImplementations§
Source§impl Secret
impl Secret
Sourcepub fn new(s: impl Into<String>) -> Self
pub fn new(s: impl Into<String>) -> Self
Create a new secret from a string-like value.
The inner string is wrapped in Zeroizing, which overwrites the memory when the
secret is dropped. This constructor is marked #[must_use] to encourage explicit
handling of the returned secret value rather than accidental discarding.
§Examples
use zeph_common::secret::Secret;
let secret = Secret::new("my_api_key");
assert_eq!(secret.expose(), "my_api_key");
// Memory is zeroized when secret is droppedSourcepub fn expose(&self) -> &str
pub fn expose(&self) -> &str
Expose the inner secret string as a borrowed reference.
Use this method to access the secret for API calls or comparisons. The reference
is bounded by the secret’s lifetime, so the underlying string cannot be dropped
while the reference is in use. Note that the string itself is not zeroized on
reference — zeroization occurs only when the containing Secret is dropped.
§Examples
use zeph_common::secret::Secret;
let secret = Secret::new("password123");
let exposed = secret.expose();
println!("Length: {}", exposed.len());