MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / hex_decode

Function hex_decode

nodedb/src/ctl/rotate_ca.rs:109–121  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

107}
108
109fn hex_decode(s: &str) -> Result<Vec<u8>, String> {
110 if !s.len().is_multiple_of(2) {
111 return Err("odd number of hex chars".into());
112 }
113 let mut out = Vec::with_capacity(s.len() / 2);
114 let bytes = s.as_bytes();
115 for chunk in bytes.chunks(2) {
116 let hi = hex_digit(chunk[0])?;
117 let lo = hex_digit(chunk[1])?;
118 out.push((hi << 4) | lo);
119 }
120 Ok(out)
121}
122
123fn hex_digit(b: u8) -> Result<u8, String> {
124 match b {

Callers 1

parse_fingerprintFunction · 0.70

Calls 4

hex_digitFunction · 0.70
lenMethod · 0.45
as_bytesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected