const-decoder2

Crates.ioconst-decoder2
lib.rsconst-decoder2
version
sourcesrc
created_at2024-12-15 10:01:05.048666
updated_at2024-12-15 10:06:48.038375
descriptionConstant functions for converting hex- and base64-encoded strings into bytes
homepage
repositoryhttps://github.com/delta4chat/const-decoder
max_upload_size
id1484035
Cargo.toml error:TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Delta 4 (delta4chat)

documentation

README

Constant Functions for Hex / Base64 Decoding

Build Status License: MIT OR Apache-2.0 rust 1.67+ required

Documentation: Docs.rs crate docs (master)

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:

[dependencies]
const-decoder = "0.4.0"

Example of usage:

use const_decoder::Decoder;
// An Ed25519 secret key.
const SECRET_KEY: [u8; 64] = Decoder::Hex.decode(
    b"9e55d1e1aa1f455b8baad9fdf975503655f8b359d542fa7e4ce84106d625b352\
      06fac1f22240cffd637ead6647188429fafda9c9cb7eae43386ac17f61115075",
);
// Alternatively, you can use `decode!` macro:
const PUBLIC_KEY: &[u8] = &const_decoder::decode!(
    Decoder::Hex,
    b"06fac1f22240cffd637ead6647188429fafda9c9cb7eae43386ac17f61115075",
);

Bech32 encoding:

use const_decoder::{Decoder, Encoding};
const BECH32: Decoder = Decoder::custom("qpzry9x8gf2tvdw0s3jn54khce6mua7l");
// Sample address from the Bech32 spec excluding the `tb1q` prefix
// and the checksum suffix.
const SAMPLE_ADDR: [u8; 32] =
    BECH32.decode(b"rp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q");

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.

Commit count: 77

cargo fmt