RustCrypto: hex-literal
This crate provides the hex! macro for converting a sequence of hexadecimal string literals to a byte array at compile time.
The macro accepts the following characters in input string literals:
'0'...'9','a'...'f','A'...'F'— hex characters which will be used in construction of the output byte array' ',:,'\r','\n','\t'— formatting characters which will be ignored
Examples
use hex;
// The macro can be used in const contexts
const DATA: = hex!;
assert_eq!;
// Both upper and lower hex values are supported
assert_eq!;
assert_eq!;
assert_eq!;
// Colon-delimited literals
assert_eq!;
// Multi-line literals
let bytes1 = hex!;
assert_eq!;
// It's possible to use several literals
// (results will be concatenated)
let bytes2 = hex!;
assert_eq!;
Using an unsupported character inside literals will result in a compilation error:
hex!; // Cyrillic "А"
hex!; // Japanese space
Сomments inside literals are not supported:
hex!;
Each literal must contain an even number of hex characters:
hex!;
License
Licensed under either of:
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.