1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

feat(checksum): odd number of hexa characters is wrong formatting

This commit is contained in:
Dorian Péron 2024-11-17 23:16:16 +01:00
parent 7c4724edc3
commit ba7c02860e

View file

@ -468,8 +468,12 @@ fn get_expected_digest_as_hex_string(caps: &Captures, chosen_regex: &Regex) -> O
if chosen_regex.as_str() == ALGO_BASED_REGEX_BASE64 { if chosen_regex.as_str() == ALGO_BASED_REGEX_BASE64 {
BASE64.decode(ck).map(hex::encode).ok() BASE64.decode(ck).map(hex::encode).ok()
} else { } else if ck.len() % 2 == 0 {
Some(str::from_utf8(ck).unwrap().to_string()) Some(str::from_utf8(ck).unwrap().to_string())
} else {
// If the length of the digest is not a multiple of 2, then it
// must be improperly formatted (1 hex digit is 2 characters)
None
} }
} }