| 91 | } |
| 92 | |
| 93 | fn 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 | |
| 109 | fn hex_decode(s: &str) -> Result<Vec<u8>, String> { |
| 110 | if !s.len().is_multiple_of(2) { |