Debug Midstate forwards

Done in preparation for adding a `length` field to `Midstate` and also
in preparation for removing the `Display` implementation (will be
justified in the patch that does it).

Currently in the `Debug` impl of `Midstate` we are calling through to
`Display` using the alternate form of printing, we can use `as_hex` to
achieve almost the same thing. Note that in `LowerHex` we use the
`fmt_hex_exact` macro that allows us to reverse the iterator however
when we later attempt to use `f.debug_struct` we cannot use the macro.

Elect to change the current behaviour to `Debug` forwards, shown by the
change to the regression test.
This commit is contained in:
Tobin C. Harding 2024-07-12 13:52:01 +10:00
parent 1d0e70b1da
commit 34dd95f909
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 4 additions and 2 deletions

View File

@ -10,6 +10,8 @@ use core::ops::Index;
use core::slice::SliceIndex; use core::slice::SliceIndex;
use core::{cmp, convert, fmt}; use core::{cmp, convert, fmt};
use hex::DisplayHex;
#[cfg(doc)] #[cfg(doc)]
use crate::sha256t; use crate::sha256t;
use crate::{sha256d, FromSliceError, HashEngine as _}; use crate::{sha256d, FromSliceError, HashEngine as _};
@ -195,7 +197,7 @@ impl fmt::Display for Midstate {
} }
impl fmt::Debug for Midstate { impl fmt::Debug for Midstate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:#}", self) } fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "0x{}", self.0.as_hex()) }
} }
impl convert::AsRef<[u8]> for Midstate { impl convert::AsRef<[u8]> for Midstate {
@ -1019,7 +1021,7 @@ mod tests {
#[test] #[test]
fn regression_midstate_debug_format() { fn regression_midstate_debug_format() {
let want = "0xc9f0c6ddea3eb37d606e63476c93f3d389500fc3f2cab338396c117ce6e4e09c"; let want = "0x9ce0e4e67c116c3938b3caf2c30f5089d3f3936c47636e607db33eeaddc6f0c9";
let got = format!("{:?}", TAP_LEAF_MIDSTATE); let got = format!("{:?}", TAP_LEAF_MIDSTATE);
assert_eq!(got, want); assert_eq!(got, want);
} }