Expand description
Hex encoding/decoding with data-independent constant time(-ish) operation.
Adapted from this C++ implementation:
https://github.com/Sc00bz/ConstTimeEncoding/blob/master/hex.cpp
Copyright (c) 2014 Steve “Sc00bz” Thomas (steve at tobtu dot com) Derived code is dual licensed MIT + Apache 2.0 (with permission from @Sc00bz)
§Usage
The main API acts as a drop-in replacement for the hex
crate
§Encoding
Use the hex::encode method:
use subtle_encoding::hex;
let encoded = hex::encode([0, 1, 2, 3, 4, 5]);
// Prints the hex encoded version: "000102030405"
println!("hex encoded: {}", String::from_utf8(encoded).unwrap());
By default hex is encoded in lower-case. To encode upper-case hex, use the hex::encode_upper method.
§Decoding
Use the hex::decode method, or hex::decode_upper for upper-case hex.
Structs§
- Hex
- Hexadecimal
Encoding
(a.k.a. Base16)
Functions§
- decode
- Decode the given data from lower-case hexadecimal, returning a
Vec<u8>
of the decoded data on success, or anError
. - decode_
upper - Decode the given data from upper-case hexadecimal, returning a
Vec<u8>
of the decoded data on success, or anError
. - encode
- Encode the given data as lower-case hexadecimal, returning a
Vec<u8>
- encode_
upper - Encode the given data as upper-case hexadecimal, returning a
Vec<u8>