Skip to content

hex

Byte/text encodings with typed errors: hexadecimal, and base64/base32 (RFC 4648).

Hex decoding accepts either case and rejects anything that is not pairs of hex digits, so trim whitespace and strip 0x prefixes before calling it. base64/base32 decoding requires = padding to a multiple of 4/8 characters and rejects it anywhere but the end.

Cargo feature hex (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features hex

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.7", default-features = false, features = ["hex"] }

Import path: helpers4::hex.

ItemWhat it does
base32_decodeDecodes s from base32 (RFC 4648 section 6).
base32_encodeEncodes data as base32 (RFC 4648 section 6), with = padding.
base64_decodeDecodes s from base64 (RFC 4648 section 4).
base64_encodeEncodes data as base64 (RFC 4648 section 4), with = padding.
decodeDecodes a hexadecimal string (either case) into bytes.
decode_arrayDecodes a hexadecimal string into a fixed-size array, e.g.
decode_to_sliceDecodes a hexadecimal string into out, which must be exactly half as long as the string.
encodeEncodes bytes as lowercase hexadecimal.
encode_upperEncodes bytes as uppercase hexadecimal.

Documented on the page of the helper that returns them.

TypeReturned by
Base32DecodeErrorbase32_decode
Base64DecodeErrorbase64_decode
DecodeErrordecode, decode_array, decode_to_slice