feat: harden community production foundation through story 1.5
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct SecretString(String);
|
||||
|
||||
impl SecretString {
|
||||
pub(crate) fn new(value: String) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
|
||||
/// Deliberate composition boundary. Never use in diagnostics or fingerprints.
|
||||
pub fn expose_secret(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn is_configured(&self) -> bool {
|
||||
!self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SecretString {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter
|
||||
.debug_tuple("SecretString")
|
||||
.field(&if self.is_configured() {
|
||||
"configured"
|
||||
} else {
|
||||
"unconfigured"
|
||||
})
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SecretString {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str(if self.is_configured() {
|
||||
"configured"
|
||||
} else {
|
||||
"unconfigured"
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user