package core:encoding/base64

⌘K
Ctrl+K
or
/

    Overview

    Base64 encoding and decoding.

    A secondary param can be used to supply a custom alphabet to encode and a matching decoding table to decode.

    If none is supplied it just uses the standard Base64 alphabet.

    By default encode emits padding. Encode options can omit it: with {.No_Padding} the output is the canonical unpadded ("raw") form of RFC 4648 section 3.2, and encoded_len reports the shorter length.

    By default decode is lenient, accepting padded and unpadded input and not checking the trailing padding bits. Decode options can enable strict (RFC 4648 section 3.5) canonical decoding: {.Strict} requires correct padding and zero trailing bits, while {.Strict, .No_Padding} accepts only canonical unpadded input.

    Types

    Decode_Error ¶

    Decode_Error :: enum int {
    	None, 
    	Invalid_Character, 
    	Invalid_Padding, 
    	Non_Canonical, 
    }

    Decode_Option ¶

    Decode_Option :: enum int {
    	// Strict requires canonical input as described in RFC 4648 section 3.5:
    	// trailing padding bits must be zero, padding must be exact, and padding
    	// characters may only appear at the end.
    	Strict, 
    	// No_Padding rejects the padding character, requiring unpadded input.
    	No_Padding, 
    }
     

    Decode_Option selects optional validation performed by the decode routines.

    Decode_Options ¶

    Decode_Options :: bit_set[Decode_Option; u8]
     

    Decode_Options is a set of Decode_Option values.

    Related Procedures With Parameters

    Encode_Option ¶

    Encode_Option :: enum int {
    	// No_Padding omits the padding character from the output (RFC 4648
    	// section 3.2), producing the canonical unpadded ("raw") form.
    	// Combine with ENC_URL_TABLE for unpadded base64url, as used by JOSE.
    	No_Padding, 
    }
     

    Encode_Option selects optional behavior of the encode routines.

    Encode_Options ¶

    Encode_Options :: bit_set[Encode_Option; u8]
     

    Encode_Options is a set of Encode_Option values.

    Related Procedures With Parameters

    Constants

    Variables

    DEC_TABLE ¶

    @(rodata)
    DEC_TABLE: [256]i8 = …

    DEC_URL_TABLE ¶

    @(rodata)
    DEC_URL_TABLE: [256]i8 = …
     

    Decoding table for Base64url variant

    ENC_TABLE ¶

    @(rodata)
    ENC_TABLE: [64]u8 = …

    ENC_URL_TABLE ¶

    @(rodata)
    ENC_URL_TABLE: [64]u8 = …
     

    Encoding table for Base64url variant

    Procedures

    decode ¶

    decode :: proc(
    	data:      string, 
    	DEC_TBL:   [256]i8 = DEC_TABLE, 
    	dst:       []u8 = nil, 
    	allocator := context.allocator, 
    	options:   bit_set[Decode_Option; u8] = Decode_Options{}, 
    ) -> (decoded: []u8, err: Error) {…}

    decode_into ¶

    decode_into :: proc(
    	w:       io.Stream, 
    	data:    string, 
    	DEC_TBL: [256]i8 = DEC_TABLE, 
    	options: bit_set[Decode_Option; u8] = Decode_Options{}, 
    ) -> Error {…}

    decode_into_buf ¶

    decode_into_buf :: proc(
    	dst:     []u8, 
    	data:    string, 
    	DEC_TBL: [256]i8 = DEC_TABLE, 
    	options: bit_set[Decode_Option; u8] = Decode_Options{}, 
    ) -> (decoded: []u8, err: Error) {…}

    decoded_len ¶

    decoded_len :: proc(data: string) -> int {…}

    encode ¶

    encode :: proc(
    	data:      []u8, 
    	ENC_TBL:   [64]u8 = ENC_TABLE, 
    	allocator := context.allocator, 
    	options:   bit_set[Encode_Option; u8] = Encode_Options{}, 
    ) -> (encoded: string, err: runtime.Allocator_Error) #optional_ok {…}

    encode_into ¶

    encode_into :: proc(
    	w:       io.Stream, 
    	data:    []u8, 
    	ENC_TBL: [64]u8 = ENC_TABLE, 
    	options: bit_set[Encode_Option; u8] = Encode_Options{}, 
    ) -> io.Error {…}

    encode_into_buf ¶

    encode_into_buf :: proc(
    	dst, data: []u8, 
    	ENC_TBL:   [64]u8 = ENC_TABLE, 
    	options:   bit_set[Encode_Option; u8] = Encode_Options{}, 
    ) -> (encoded: []u8, err: Error) {…}

    encoded_len ¶

    encoded_len :: proc(data: []u8, options: bit_set[Encode_Option; u8] = Encode_Options{}) -> int {…}

    Procedure Groups

    This section is empty.

    Source Files

    Generation Information

    Generated with odin version dev-2026-10 (vendor "odin") Windows_amd64 @ 2026-10-12 23:46:18.383355400 +0000 UTC