aboutsummaryrefslogtreecommitdiffstats
path: root/rs/common
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-01-24 18:07:09 +0100
committerLibravatar Rutger Broekhoff2024-01-24 18:07:09 +0100
commitdbe5de070b8b4c86abe27bb3378e1685632dfdab (patch)
treeb578aeb36af41cef567bec5b3edabf3ddd460839 /rs/common
parent955ca49ef8a1db0e8791fc21daf1b3d302361593 (diff)
downloadgitolfs3-dbe5de070b8b4c86abe27bb3378e1685632dfdab.tar.gz
gitolfs3-dbe5de070b8b4c86abe27bb3378e1685632dfdab.zip
Write claim validation test
Diffstat (limited to 'rs/common')
-rw-r--r--rs/common/src/lib.rs16
1 files changed, 12 insertions, 4 deletions
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> {
136 for (i, c) in value.bytes().enumerate() { 136 for (i, c) in value.bytes().enumerate() {
137 if let Some(b) = decode_nibble(c) { 137 if let Some(b) = decode_nibble(c) {
138 if i % 2 == 0 { 138 if i % 2 == 0 {
139 buf[i / 2] |= b; 139 buf[i / 2] |= b << 4;
140 } else { 140 } else {
141 buf[i / 2] = b << 4; 141 buf[i / 2] |= b;
142 } 142 }
143 } else { 143 } else {
144 return Err(ParseHexError::InvalidCharacter); 144 return Err(ParseHexError::InvalidCharacter);
@@ -236,8 +236,16 @@ impl<B: AsRef<[u8]>> fmt::Display for HexFmt<B> {
236 let HexFmt(buf) = self; 236 let HexFmt(buf) = self;
237 for b in buf.as_ref() { 237 for b in buf.as_ref() {
238 let (high, low) = (b >> 4, b & 0xF); 238 let (high, low) = (b >> 4, b & 0xF);
239 let highc = if high < 10 { b'0' + high } else { b'a' + high }; 239 let highc = if high < 10 {
240 let lowc = if low < 10 { b'0' + low } else { b'a' + low }; 240 high + b'0'
241 } else {
242 high - 10 + b'a'
243 };
244 let lowc = if low < 10 {
245 low + b'0'
246 } else {
247 low - 10 + b'a'
248 };
241 f.write_char(highc as char)?; 249 f.write_char(highc as char)?;
242 f.write_char(lowc as char)?; 250 f.write_char(lowc as char)?;
243 } 251 }