From a829d79f5a73561b6ffeaeddab68c254cc2e5659 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 8 May 2023 06:49:12 -0600 Subject: [PATCH] pkcs1v15: have `fmt` impls call `SignatureEncoding::to_bytes` 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. --- src/pkcs1v15/signature.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pkcs1v15/signature.rs b/src/pkcs1v15/signature.rs index 552ab4f4..a640da32 100644 --- a/src/pkcs1v15/signature.rs +++ b/src/pkcs1v15/signature.rs @@ -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(()) } }