Skip to content

encoding.base32 #

Description

encoding.base32 encodes and decodes Base32 data using the standard or hexadecimal alphabet. Decoders reject bytes outside their alphabet.

Custom alphabets must contain exactly 32 distinct bytes, excluding CR, LF, and the padding byte. Encoding constructors panic when these requirements are violated.

With no_padding, the final group may contain 2, 4, 5, or 7 symbols, or a complete group of 8. Incomplete groups of 1, 3, or 6 symbols return an illegal Base32 data error.

Decoding ignores CR and LF bytes in the input, including inside an encoded quantum and after padding. Other whitespace is not stripped.

Constants #

const std_padding = `=` // Standard padding character
const no_padding = u8(-1) // No padding
const std_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'.bytes()
const hex_alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUV'.bytes()

fn decode #

fn decode(src []u8) ![]u8

decode decodes a byte array src using Base32 and returns the decoded bytes or a corrupt_input_error_msg error.

fn decode_string_to_string #

fn decode_string_to_string(src string) !string

decode_string_to_string decodes a V string src using Base32 and returns the decoded string or a corrupt_input_error_msg error.

fn decode_to_string #

fn decode_to_string(src []u8) !string

decode_to_string decodes a byte array src using Base32 and returns the decoded string or a corrupt_input_error_msg error.

fn encode #

fn encode(src []u8) []u8

encode encodes a byte array src using Base32 and returns the encoded bytes.

fn encode_string_to_string #

fn encode_string_to_string(src string) string

encode_string_to_string encodes the V string src using Base32 and returns the encoded bytes as a V string.

fn encode_to_string #

fn encode_to_string(src []u8) string

encode_to_string encodes a byte array src using Base32 and returns the encoded bytes as a V string.

fn new_encoding #

fn new_encoding(alphabet []u8) Encoding

new_encoding returns a Base32 Encoding with standard alphabets and standard padding.

fn new_encoding_with_padding #

fn new_encoding_with_padding(alphabet []u8, padding_char u8) Encoding

new_encoding_with_padding returns a Base32 Encoding with specified encoding alphabets and a specified padding_char. Panics unless the alphabet has exactly 32 distinct bytes without CR or LF. The padding_char must not be '\r' or '\n', must not be contained in the Encoding's alphabet and must be a rune equal or below '\xff'.

fn new_std_encoding #

fn new_std_encoding() Encoding

new_std_encoding creates a standard Base32 Encoding as defined in RFC 4648.

fn new_std_encoding_with_padding #

fn new_std_encoding_with_padding(padding u8) Encoding

new_std_encoding creates a standard Base32 Encoding identical to new_std_encoding but with a specified character padding, or no_padding to disable padding. The padding character must not be '\r' or '\n', must not be contained in the Encoding's alphabet and must be a rune equal or below '\xff'.

fn (Encoding) encode_to_string #

fn (enc &Encoding) encode_to_string(src []u8) string

encode_to_string encodes the Base32 encoding of src with the encoding enc and returns the encoded bytes as a V string.

fn (Encoding) encode_string_to_string #

fn (enc &Encoding) encode_string_to_string(src string) string

encode_string_to_string encodes a V string src using Base32 with the encoding enc and returns the encoded bytes as a V string.

fn (Encoding) decode_string #

fn (enc &Encoding) decode_string(src string) ![]u8

decode_string decodes a V string src using Base32 with the encoding enc and returns the decoded bytes or a corrupt_input_error_msg error.

fn (Encoding) decode_string_to_string #

fn (enc &Encoding) decode_string_to_string(src string) !string

decode_string_to_string decodes a V string src using Base32 with the encoding enc and returns the decoded V string or a corrupt_input_error_msg error.

fn (Encoding) decode #

fn (enc &Encoding) decode(src []u8) ![]u8

decode decodes src using the encoding enc. It returns the decoded bytes written or a corrupt_input_error_msg error. New line characters (\r and \n) are ignored. Without padding, final groups of 1, 3 or 6 symbols are invalid.