From dbe5de070b8b4c86abe27bb3378e1685632dfdab Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Wed, 24 Jan 2024 18:07:09 +0100 Subject: Write claim validation test --- rs/common/src/lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'rs/common/src') diff --git a/rs/common/src/lib.rs b/rs/common/src/lib.rs index 27205bd..89c3286 100644 --- a/rs/common/src/lib.rs +++ b/rs/common/src/lib.rs @@ -136,9 +136,9 @@ fn parse_hex_exact(value: &str, buf: &mut [u8]) -> Result<(), ParseHexError> { for (i, c) in value.bytes().enumerate() { if let Some(b) = decode_nibble(c) { if i % 2 == 0 { - buf[i / 2] |= b; + buf[i / 2] |= b << 4; } else { - buf[i / 2] = b << 4; + buf[i / 2] |= b; } } else { return Err(ParseHexError::InvalidCharacter); @@ -236,8 +236,16 @@ impl> fmt::Display for HexFmt { let HexFmt(buf) = self; for b in buf.as_ref() { let (high, low) = (b >> 4, b & 0xF); - let highc = if high < 10 { b'0' + high } else { b'a' + high }; - let lowc = if low < 10 { b'0' + low } else { b'a' + low }; + let highc = if high < 10 { + high + b'0' + } else { + high - 10 + b'a' + }; + let lowc = if low < 10 { + low + b'0' + } else { + low - 10 + b'a' + }; f.write_char(highc as char)?; f.write_char(lowc as char)?; } -- cgit v1.2.3