pub fn decode_hex(hex: &str) -> Result<Vec<u8>, String>Expand description
Decode hexadecimal string to bytes.
ยงExamples
use chie_shared::decode_hex;
// Decode hex string
let bytes = decode_hex("deadbeef").unwrap();
assert_eq!(bytes, vec![0xde, 0xad, 0xbe, 0xef]);
// Roundtrip encoding/decoding
let original = vec![1, 2, 3, 255];
let hex = chie_shared::encode_hex(&original);
let decoded = decode_hex(&hex).unwrap();
assert_eq!(original, decoded);
// Error on odd length
assert!(decode_hex("abc").is_err());
// Error on invalid hex
assert!(decode_hex("xyz").is_err());