diff --git a/src/lib.rs b/src/lib.rs index b47ee68..47aa9fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -322,10 +322,11 @@ impl Drop for SecretKey { self.zero_secret(); } } + /// A debug statement where the secret prime field element is redacted. impl fmt::Debug for SecretKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("SecretKey").field(&"...").finish() + f.debug_tuple("SecretKey").field(&DebugDots).finish() } } @@ -422,7 +423,7 @@ impl Distribution for Standard { impl fmt::Debug for SecretKeyShare { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("SecretKeyShare").field(&"...").finish() + f.debug_tuple("SecretKeyShare").field(&DebugDots).finish() } } @@ -519,7 +520,7 @@ impl Ciphertext { } /// A decryption share. A threshold of decryption shares can be used to decrypt a message. -#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)] +#[derive(Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct DecryptionShare(#[serde(with = "serde_impl::projective")] G1); impl Distribution for Standard { @@ -534,6 +535,12 @@ impl Hash for DecryptionShare { } } +impl fmt::Debug for DecryptionShare { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("DecryptionShare").field(&DebugDots).finish() + } +} + /// A public key and an associated set of public key shares. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct PublicKeySet { @@ -773,6 +780,16 @@ fn into_fr_plus_1(x: I) -> Fr { result } +/// Type that implements `Debug` printing three dots. This can be used to hide the contents of a +/// field in a `Debug` implementation. +struct DebugDots; + +impl fmt::Debug for DebugDots { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "...") + } +} + #[cfg(test)] mod tests { use super::*;