diff options
author | Kai Michaelis <kai@sequoia-pgp.org> | 2018-10-17 20:43:16 +0200 |
---|---|---|
committer | Kai Michaelis <kai@sequoia-pgp.org> | 2018-10-17 20:43:16 +0200 |
commit | a7d33ab7cc3a752b0fe8e996e49ce3248fd2079a (patch) | |
tree | a117617a339e2df5d8120039c5fa0b3cb663df45 /openpgp/src | |
parent | d2f1b8c9b07daa2845613b5fb2a1dfd0499d938a (diff) |
openpgp: don't show SecretKey values in release mode
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/mpis.rs | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/openpgp/src/mpis.rs b/openpgp/src/mpis.rs index ea3f74e3..54065bf6 100644 --- a/openpgp/src/mpis.rs +++ b/openpgp/src/mpis.rs @@ -249,7 +249,7 @@ impl Arbitrary for PublicKey { /// /// Provides a typed and structured way of storing multiple MPIs in /// packets. -#[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum SecretKey { /// RSA secret key. RSA { @@ -302,6 +302,46 @@ pub enum SecretKey { }, } +impl fmt::Debug for SecretKey { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if cfg!(debug) { + match self { + &SecretKey::RSA{ ref d, ref p, ref q, ref u } => + write!(f, "RSA {{ d: {:?}, p: {:?}, q: {:?}, u: {:?} }}", d, p, q, u), + &SecretKey::DSA{ ref x } => + write!(f, "DSA {{ x: {:?} }}", x), + &SecretKey::Elgamal{ ref x } => + write!(f, "Elgamal {{ x: {:?} }}", x), + &SecretKey::EdDSA{ ref scalar } => + write!(f, "EdDSA {{ scalar: {:?} }}", scalar), + &SecretKey::ECDSA{ ref scalar } => + write!(f, "ECDSA {{ scalar: {:?} }}", scalar), + &SecretKey::ECDH{ ref scalar } => + write!(f, "ECDH {{ scalar: {:?} }}", scalar), + &SecretKey::Unknown{ ref mpis, ref rest } => + write!(f, "Unknown {{ mips: {:?}, rest: {:?} }}", mpis, rest), + } + } else { + match self { + &SecretKey::RSA{ .. } => + f.write_str("RSA { <Redacted> }"), + &SecretKey::DSA{ .. } => + f.write_str("DSA { <Redacted> }"), + &SecretKey::Elgamal{ .. } => + f.write_str("Elgamal { <Redacted> }"), + &SecretKey::EdDSA{ .. } => + f.write_str("EdDSA { <Redacted> }"), + &SecretKey::ECDSA{ .. } => + f.write_str("ECDSA { <Redacted> }"), + &SecretKey::ECDH{ .. } => + f.write_str("ECDH { <Redacted> }"), + &SecretKey::Unknown{ .. } => + f.write_str("Unknown { <Redacted> }"), + } + } + } +} + impl Drop for SecretKey { fn drop(&mut self) { use self::SecretKey::*; |