Skip to main content

decode

Function decode 

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

Decodes a hexadecimal string (either case) into bytes.

The string must be made of digit pairs only: surrounding whitespace, a 0x prefix or separators are errors, so trim or strip them first.

§Arguments

  • hex - The hexadecimal string to decode.

§Errors

DecodeError::OddLength for an odd number of characters, DecodeError::InvalidChar for a character that is not a hex digit.

§Examples

use helpers4::hex::decode;

assert_eq!(decode("DeadBeef")?, vec![0xde, 0xad, 0xbe, 0xef]);
assert!(decode("abc").is_err());