yabase/base16
Values
pub fn decode(
input: String,
) -> Result(BitArray, error.CodecError)
Decode a hexadecimal string to a BitArray.
pub fn decode_strict(
input: String,
) -> Result(BitArray, error.CodecError)
Decode input and additionally reject non-canonical encodings
per RFC 4648 §8: the canonical Base 16 form is uppercase
(0-9 A-F). Useful for HMAC / TOTP / WebAuthn / content-
addressable storage and any signature-verification context where
the encoded string itself is part of the contract — strict mode
rejects the lowercase form (encode_lowercase/1’s output) as
non-canonical even though it decodes to the same bytes through
the lenient decode/1.
Returns Error(NonCanonical) when the input is not byte-equal
to encode(decode(input)). Other failure modes
(InvalidCharacter, InvalidLength) are surfaced unchanged from
decode/1.
pub fn encode(data: BitArray) -> String
Encode a BitArray to an uppercase hexadecimal string per RFC 4648 §8 (the canonical Base 16 encoding).
Use encode_lowercase/1 when interoperating with tools that
emit lowercase hex (e.g. sha256sum, IPFS multibase prefix f,
many JSON Web Token implementations); the decoder accepts either
case, so round-trips work in both directions.
pub fn encode_lowercase(data: BitArray) -> String
Encode a BitArray to a lowercase hexadecimal string. Use this
when interoperating with tools that expect the lowercase variant
(sha256sum shell output, IPFS multibase prefix f, etc.). The
canonical RFC 4648 §8 form is uppercase — see encode/1.