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

Function parse_fingerprint

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

Source from the content-addressed store, hash-verified

91}
92
93fn parse_fingerprint(s: &str) -> Result<[u8; 32], String> {
94 let trimmed = s.trim();
95 let bytes = hex_decode(trimmed).map_err(|e| format!("fingerprint is not valid hex: {e}"))?;
96 let mut out = [0u8; 32];
97 match bytes.len() {
98 8 => out[..8].copy_from_slice(&bytes),
99 32 => out.copy_from_slice(&bytes),
100 n => {
101 return Err(format!(
102 "fingerprint must be 8 bytes (16 hex chars) or 32 bytes (64 hex chars), got {n}"
103 ));
104 }
105 }
106 Ok(out)
107}
108
109fn hex_decode(s: &str) -> Result<Vec<u8>, String> {
110 if !s.len().is_multiple_of(2) {

Callers 2

finalizeFunction · 0.85

Calls 2

hex_decodeFunction · 0.70
lenMethod · 0.45

Tested by 1