tk_rs/
utils.rs

1pub fn hex_to_bytes(hex: &str) -> Result<Vec<u8>, anyhow::Error> {
2    (0..hex.len())
3        .step_by(2)
4        .map(|i| u8::from_str_radix(&hex[i..i + 2], 16))
5        .collect::<Result<Vec<_>, _>>()
6        .map_err(|e| anyhow::anyhow!(e.to_string()))
7}
8
9pub fn bytes_to_hex(bytes: &[u8]) -> Result<String, anyhow::Error> {
10    Ok(bytes.iter().map(|byte| format!("{:02x}", byte)).collect())
11}