From 3c7f5458a83e5c5d6456b5bc05244168aced2ab1 Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Tue, 28 Nov 2023 16:35:05 -0500 Subject: [PATCH] wip: review feedback --- src/lib.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b733bb5..cd7aba2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -523,7 +523,10 @@ impl DerInner<'_> { // Format an iterator of u8 into a hex string fn hex<'a>(f: &mut fmt::Formatter<'_>, payload: impl IntoIterator) -> fmt::Result { - for b in payload { + for (i, b) in payload.into_iter().enumerate() { + if i == 0 { + write!(f, "0x")?; + } write!(f, "{:02x}", b)?; } Ok(()) @@ -531,15 +534,17 @@ fn hex<'a>(f: &mut fmt::Formatter<'_>, payload: impl IntoIterator #[cfg(feature = "std")] mod tests { + use super::*; + #[test] fn der_debug() { - let der = super::Der::from_slice(&[0x01, 0x02, 0x03]); - assert_eq!(format!("{:?}", der), "010203"); + let der = Der::from_slice(&[0x01, 0x02, 0x03]); + assert_eq!(format!("{:?}", der), "0x010203"); } #[test] - fn algid_debug() { - let algid = super::AlgorithmIdentifier::from_slice(&[0x01, 0x02, 0x03]); - assert_eq!(format!("{:?}", algid), "010203"); + fn alg_id_debug() { + let alg_id = AlgorithmIdentifier::from_slice(&[0x01, 0x02, 0x03]); + assert_eq!(format!("{:?}", alg_id), "0x010203"); } }