(s: &str)
| 107 | } |
| 108 | |
| 109 | fn 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 | |
| 123 | fn hex_digit(b: u8) -> Result<u8, String> { |
| 124 | match b { |
no test coverage detected