Skip to content

Commit 69f44d9

Browse files
committed
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`.
1 parent 26921a3 commit 69f44d9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ecdsa/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,19 @@ impl fmt::Debug for Signature {
3232
impl fmt::Display for Signature {
3333
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3434
let sig = self.serialize_der();
35-
for v in sig.iter() {
35+
sig.fmt(f)
36+
}
37+
}
38+
39+
impl fmt::Debug for SerializedSignature {
40+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41+
fmt::Display::fmt(self, f)
42+
}
43+
}
44+
45+
impl fmt::Display for SerializedSignature {
46+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47+
for v in self.data.iter().take(self.len) {
3648
write!(f, "{:02x}", v)?;
3749
}
3850
Ok(())

0 commit comments

Comments
 (0)