orchard: Better Debug impls for some keys

This commit is contained in:
Deirdre Connolly 2021-04-03 19:14:34 -04:00 committed by Deirdre Connolly
parent eb68caf14c
commit db8f9cb81a
2 changed files with 25 additions and 17 deletions

6
Cargo.lock generated
View File

@ -1523,9 +1523,9 @@ source = "git+https://github.com/zcash/halo2.git?branch=main#b079624ea78b4a07d44
dependencies = [
"blake2b_simd",
"crossbeam-utils 0.8.0",
"ff 0.9.0",
"ff",
"funty",
"group 0.9.0",
"group",
"num_cpus",
"pasta_curves",
"rand 0.8.1",
@ -4448,7 +4448,7 @@ dependencies = [
"fpe",
"funty",
"futures 0.3.14",
"group 0.9.0",
"group",
"halo2",
"hex",
"itertools 0.10.0",

View File

@ -862,14 +862,18 @@ pub struct TransmissionKey(pub pallas::Affine);
impl fmt::Debug for TransmissionKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// This will panic if the public key is the identity, which is bad news
// bears.
let (x, y) = self.0.get_xy().unwrap();
let mut d = f.debug_struct("TransmissionKey");
f.debug_struct("TransmissionKey")
.field("x", &hex::encode(x.to_bytes()))
.field("y", &hex::encode(y.to_bytes()))
.finish()
match self.0.get_xy().into() {
Some((x, y)) => d
.field("x", &hex::encode(x.to_bytes()))
.field("y", &hex::encode(y.to_bytes()))
.finish(),
None => d
.field("x", &hex::encode(pallas::Base::zero().to_bytes()))
.field("y", &hex::encode(pallas::Base::zero().to_bytes()))
.finish(),
}
}
}
@ -921,14 +925,18 @@ pub struct EphemeralPublicKey(#[serde(with = "serde_helpers::Affine")] pub palla
impl fmt::Debug for EphemeralPublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// This will panic if the public key is the identity, which is bad news
// bears.
let (x, y) = self.0.get_xy().unwrap();
let mut d = f.debug_struct("EphemeralPublicKey");
f.debug_struct("EphemeralPublicKey")
.field("x", &hex::encode(x.to_bytes()))
.field("y", &hex::encode(y.to_bytes()))
.finish()
match self.0.get_xy().into() {
Some((x, y)) => d
.field("x", &hex::encode(x.to_bytes()))
.field("y", &hex::encode(y.to_bytes()))
.finish(),
None => d
.field("x", &hex::encode(pallas::Base::zero().to_bytes()))
.field("y", &hex::encode(pallas::Base::zero().to_bytes()))
.finish(),
}
}
}