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>) -> Secret
pub fn new(s: impl Into<String>) -> Secret
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());Trait Implementations§
Source§impl<'de> Deserialize<'de> for Secret
impl<'de> Deserialize<'de> for Secret
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Secret, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Secret, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Secret
impl RefUnwindSafe for Secret
impl Send for Secret
impl Sync for Secret
impl Unpin for Secret
impl UnsafeUnpin for Secret
impl UnwindSafe for Secret
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request