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

Function decode_hex

blobby/src/bin/encode.rs:28–41  ·  view source on GitHub ↗
(data: &str)

Source from the content-addressed store, hash-verified

26 }
27
28 fn decode_hex(data: &str) -> io::Result<Vec<u8>> {
29 if data.len() % 2 != 0 {
30 let msg = "Invalid hex string: length is not even";
31 return Err(io::Error::new(io::ErrorKind::InvalidData, msg));
32 }
33 data.as_bytes()
34 .chunks_exact(2)
35 .map(|chunk| {
36 let a = decode_hex_char(chunk[0])?;
37 let b = decode_hex_char(chunk[1])?;
38 Ok((a << 4) | b)
39 })
40 .collect()
41 }
42
43 fn encode(reader: impl BufRead, mut writer: impl Write) -> io::Result<usize> {
44 let mut blobs = Vec::new();

Callers 1

encodeFunction · 0.85

Calls 3

decode_hex_charFunction · 0.85
lenMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected