MCPcopy Create free account
hub / github.com/RustCrypto/utils / decode_hex_char

Function decode_hex_char

blobby/src/bin/encode.rs:15–26  ·  view source on GitHub ↗
(b: u8)

Source from the content-addressed store, hash-verified

13 use std::{env, fs::File};
14
15 fn decode_hex_char(b: u8) -> io::Result<u8> {
16 let res = match b {
17 b'0'..=b'9' => b - b'0',
18 b'a'..=b'f' => b - b'a' + 10,
19 b'A'..=b'F' => b - b'A' + 10,
20 _ => {
21 let msg = "Invalid hex string: invalid byte {b}";
22 return Err(io::Error::new(io::ErrorKind::InvalidData, msg));
23 }
24 };
25 Ok(res)
26 }
27
28 fn decode_hex(data: &str) -> io::Result<Vec<u8>> {
29 if data.len() % 2 != 0 {

Callers 1

decode_hexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected