From caca664b202bc6edcd8f4653ff2371816e0f05f0 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 5 Apr 2022 22:38:10 +0000 Subject: [PATCH] Make `Debug` impl for `TransmittedNoteCiphertext` less verbose We now print the ciphertexts as hex bytes, for which we unambiguously encode them in RPC outputs (vs 32-byte values which are more complex). --- Cargo.toml | 2 +- src/note.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9e81b34..6d6bd981 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ fpe = "0.5" group = "0.11" halo2_gadgets = "=0.1.0-beta.3" halo2_proofs = "=0.1.0-beta.4" +hex = "0.4" lazy_static = "1" memuse = { version = "0.2", features = ["nonempty"] } pasta_curves = "0.3" @@ -48,7 +49,6 @@ plotters = { version = "0.3.0", optional = true } [dev-dependencies] criterion = "0.3" halo2_gadgets = { version = "=0.1.0-beta.3", features = ["test-dependencies"] } -hex = "0.4" proptest = "1.0.0" zcash_note_encryption = { version = "0.1", features = ["pre-zip-212"] } diff --git a/src/note.rs b/src/note.rs index fa640935..8659493a 100644 --- a/src/note.rs +++ b/src/note.rs @@ -1,4 +1,6 @@ //! Data structures used for note construction. +use std::fmt; + use group::GroupEncoding; use pasta_curves::pallas; use rand::RngCore; @@ -236,7 +238,7 @@ impl Note { } /// An encrypted note. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct TransmittedNoteCiphertext { /// The serialization of the ephemeral public key pub epk_bytes: [u8; 32], @@ -247,6 +249,16 @@ pub struct TransmittedNoteCiphertext { pub out_ciphertext: [u8; 80], } +impl fmt::Debug for TransmittedNoteCiphertext { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TransmittedNoteCiphertext") + .field("epk_bytes", &self.epk_bytes) + .field("enc_ciphertext", &hex::encode(self.enc_ciphertext)) + .field("out_ciphertext", &hex::encode(self.out_ciphertext)) + .finish() + } +} + /// Generators for property testing. #[cfg(any(test, feature = "test-dependencies"))] #[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))]