pub struct SecretString(/* private fields */);Expand description
Minimal no-new-dependency replacement for secrecy::SecretString.
Exposes the secret only on explicit .expose_secret() calls. The secret
cannot be implicitly leaked by the Debug implementation, e.g. in logs.
Retains serialization/deserialization via serde.
Deviations from secrecy:
- Does not zero on
Drop: the heap bytes remain after deallocation, and, e.g., a core dump could contain leaked secrets. - Implements
Clone:secrecyuses its ownSecretBoxsmart pointer for space efficiency. Since we can reasonably expect only a handful of secrets in memory for TinyHarness, that optimization is not worth the added complexity.
Implementations§
Source§impl SecretString
impl SecretString
pub fn new(s: impl Into<String>) -> Self
Sourcepub fn expose_secret(&self) -> &str
pub fn expose_secret(&self) -> &str
Expose the underlying secret. Use this as the point the actual value is required (e.g., in constructing an HTTP request). Do not log the exposed value.
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn masked(&self) -> String
Trait Implementations§
Source§impl Clone for SecretString
impl Clone for SecretString
Source§impl Debug for SecretString
impl Debug for SecretString
Source§impl Default for SecretString
impl Default for SecretString
Source§impl<'de> Deserialize<'de> for SecretString
impl<'de> Deserialize<'de> for SecretString
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for SecretString
Source§impl Hash for SecretString
impl Hash for SecretString
Source§impl Ord for SecretString
impl Ord for SecretString
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for SecretString
impl PartialEq for SecretString
Source§impl PartialOrd for SecretString
impl PartialOrd for SecretString
Source§impl Serialize for SecretString
impl Serialize for SecretString
impl StructuralPartialEq for SecretString
Auto Trait Implementations§
impl Forget for SecretString
impl Freeze for SecretString
impl RefUnwindSafe for SecretString
impl Send for SecretString
impl Sync for SecretString
impl Unpin for SecretString
impl UnsafeUnpin for SecretString
impl UnwindSafe for SecretString
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.