#[cfg(feature = "alloc")]
#[must_use = "dropping EncodedSecret may immediately zeroize encoded output"]
pub struct EncodedSecret(zeroize::Zeroizing<alloc::string::String>);
#[cfg(feature = "alloc")]
impl EncodedSecret {
#[cfg(any(
feature = "encoding-hex",
feature = "encoding-base64",
feature = "encoding-bech32",
feature = "encoding-bech32m",
))]
#[inline(always)]
pub(crate) fn new(s: alloc::string::String) -> Self {
Self(zeroize::Zeroizing::new(s))
}
#[inline(always)]
pub fn into_inner(mut self) -> alloc::string::String {
core::mem::take(&mut self.0)
}
#[inline(always)]
pub fn into_zeroizing(self) -> zeroize::Zeroizing<alloc::string::String> {
self.0
}
}
#[cfg(feature = "alloc")]
impl core::ops::Deref for EncodedSecret {
type Target = str;
#[inline(always)]
fn deref(&self) -> &str {
&self.0
}
}
#[cfg(feature = "alloc")]
impl core::fmt::Debug for EncodedSecret {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("[REDACTED]")
}
}
#[cfg(feature = "alloc")]
impl core::convert::AsRef<str> for EncodedSecret {
fn as_ref(&self) -> &str {
&self.0
}
}
#[cfg(feature = "alloc")]
impl core::convert::AsRef<[u8]> for EncodedSecret {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
#[cfg(feature = "alloc")]
impl core::fmt::Display for EncodedSecret {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Display::fmt(&**self, f)
}
}