From 7dd5637036ac2f477f8bcf74bd3692ef5fbd581a Mon Sep 17 00:00:00 2001 From: Mark Logan <103447440+mystenmark@users.noreply.github.com> Date: Fri, 22 Jul 2022 16:47:13 -0700 Subject: [PATCH] Restore previous Debug impl for PublicKeyBytes (#3445) --- crates/sui-types/src/crypto.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/sui-types/src/crypto.rs b/crates/sui-types/src/crypto.rs index 81bf1a8cd6415..e0e03c9723d2e 100644 --- a/crates/sui-types/src/crypto.rs +++ b/crates/sui-types/src/crypto.rs @@ -47,9 +47,20 @@ pub type AggregateAccountSignature = Ed25519AggregateSignature; // #[serde_as] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct PublicKeyBytes(#[serde_as(as = "Readable")] [u8; PublicKey::LENGTH]); +impl PublicKeyBytes { + fn fmt_impl( + &self, + f: &mut std::fmt::Formatter<'_>, + ) -> std::result::Result<(), std::fmt::Error> { + let s = hex::encode(&self.0); + write!(f, "k#{}", s)?; + Ok(()) + } +} + impl TryFrom for PublicKey { type Error = signature::Error; @@ -70,11 +81,15 @@ impl AsRef<[u8]> for PublicKeyBytes { } } +impl std::fmt::Debug for PublicKeyBytes { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { + self.fmt_impl(f) + } +} + impl Display for PublicKeyBytes { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { - let s = hex::encode(&self.0); - write!(f, "k#{}", s)?; - Ok(()) + self.fmt_impl(f) } }