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

Function hex_decode

nodedb-cluster/src/auth/join_token.rs:127–138  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

125}
126
127fn hex_decode(s: &str) -> Result<Vec<u8>, TokenError> {
128 let mut out = Vec::with_capacity(s.len() / 2);
129 for chunk in s.as_bytes().chunks(2) {
130 if chunk.len() != 2 {
131 return Err(TokenError::InvalidHex);
132 }
133 let hi = hex_digit(chunk[0]).ok_or(TokenError::InvalidHex)?;
134 let lo = hex_digit(chunk[1]).ok_or(TokenError::InvalidHex)?;
135 out.push((hi << 4) | lo);
136 }
137 Ok(out)
138}
139
140fn hex_digit(b: u8) -> Option<u8> {
141 match b {

Callers 3

token_hashFunction · 0.70
verify_tokenFunction · 0.70
token_hash_stableFunction · 0.70

Calls 4

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

Tested by 1

token_hash_stableFunction · 0.56