Constant Functions for Hex / Base64 Decoding
Constant functions for converting hex- and base64-encoded strings into bytes in Rust. Works on stable Rust and in no-std environments. Base-(2,4,8,16,32,64) encodings with custom alphabets are supported as well.
Usage
Add this to your Crate.toml
:
[]
= "0.3.0"
Example of usage:
use Decoder;
// An Ed25519 secret key.
const SECRET_KEY: = Hex.decode;
Bech32 encoding:
use ;
const BECH32: Decoder = custom;
// Sample address from the Bech32 spec excluding the `tb1q` prefix
// and the checksum suffix.
const SAMPLE_ADDR: =
BECH32.decode;
See more examples in the crate docs.
Alternatives
hex-literal
and binary_macros
crates expose similar functionality
as procedural macros. Because of this, macros cannot be used in no-std environments,
while this approach can.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in const-decoder
by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.