Manually implement Debug for SerializedSignature

Currently we have an implementation of `Debug` (also used by `Display`)
for `Signature` that first converts the sig to a `SerializedSignature`
then prints it as hex.

We would like to have an implementation of `Debug` for
`SerializedSignature`, this cannot be derived because of the `data: [u8;
field]`. We can manually implement `Debug` for `SerializedSignature`
exactly as it is currently done for `Signature` and call this new
implementation from `Signature::fmt()`.

This code path is already tested in `lib.rs` in the test function
`signature_display`.
This commit is contained in:
Tobin Harding 2022-01-07 10:31:15 +11:00
parent 26921a31b8
commit 69f44d9301
1 changed files with 13 additions and 1 deletions

View File

@ -32,7 +32,19 @@ impl fmt::Debug for Signature {
impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let sig = self.serialize_der();
for v in sig.iter() {
sig.fmt(f)
}
}
impl fmt::Debug for SerializedSignature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for SerializedSignature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for v in self.data.iter().take(self.len) {
write!(f, "{:02x}", v)?;
}
Ok(())