Skip to content

Commit

Permalink
pkcs1v15: have fmt impls call SignatureEncoding::to_bytes (#330)
Browse files Browse the repository at this point in the history
The `fmt::{LowerHex, UpperHex}` impls, with the latter called
vicariously via `fmt::Display`, were showing the unpadded signature
rather than the padded one.

This changes these impls to call `SignatureEncoding::to_bytes` first
before displaying the signature.
  • Loading branch information
tarcieri committed May 8, 2023
1 parent 7a58281 commit 09254b0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ impl Debug for Signature {

impl LowerHex for Signature {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{:x}", &self.inner)
for byte in self.to_bytes().iter() {
write!(f, "{:02x}", byte)?;
}
Ok(())
}
}

impl UpperHex for Signature {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{:X}", &self.inner)
for byte in self.to_bytes().iter() {
write!(f, "{:02X}", byte)?;
}
Ok(())
}
}

Expand Down

0 comments on commit 09254b0

Please sign in to comment.