1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Secret strings

use super::{CloneableSecret, DebugSecret, Secret, ExposeSecret};
use alloc::string::String;
use alloc::borrow::ToOwned;
use core::ops::Deref;

/// Secret strings
pub type SecretString = Secret<String>;

impl DebugSecret for SecretString {
    fn debug_secret() -> &'static str {
        "R3DACT3D::<String>::S3CR3T"
    }
}
impl DebugSecret for String {
    fn debug_secret() -> &'static str {
        "R3DACT3D::<String>::S3CR3T"
    }
}
impl PartialEq for SecretString {
    fn eq(&self, other: &Self) -> bool {
        self.expose_secret() == other.expose_secret()
    }
}

impl Eq for SecretString {}

impl CloneableSecret for String {}

impl alloc::fmt::Display for SecretString {
    fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
        write!(f, "R3DACT3D::<String>::S3CR3T")
    }
}

impl Default for SecretString {
    fn default() -> Self {
        SecretString::new("R3DACT3D::<String>::S3CR3T".to_owned())
    }
}


impl Deref for SecretString {
    type Target = String;

    fn deref(&self) -> &String {
        &self.expose_secret()
    }
}