Skip to main content

decode

Function decode 

Source
pub fn decode(data: &str) -> Result<Vec<u8>, DecodeHexError>
Expand description

ยงExample:

use otp::encoding::hex;

let input = "090A0B0C";
let decoded = hex::decode(input).expect("Decoding failed");
assert_eq!([9, 10, 11, 12], decoded.as_slice());

let input_odd_err = "090A0B0CZ";
let result_odd_err = hex::decode(input_odd_err);
assert!(matches!(result_odd_err, Err(hex::DecodeHexError::InvalidLength)));

let input_parse_int_err = "090A0B0CZZ";
let result_parse_int_err = hex::decode(input_parse_int_err);
assert!(matches!(result_parse_int_err, Err(hex::DecodeHexError::ParseInt(_))));