base32

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 2 Imported by: 2

README

base32

-- import "github.com/go-i2p/common/base32"

base32.svg

Package base32 implements utilities for encoding and decoding text using I2P's alphabet.

This package provides I2P-specific base32 encoding/decoding functionality using RFC 3548 with lowercase characters as specified by the I2P protocol. The implementation supports encoding binary data to human-readable strings for I2P destinations, router identifiers, and other network components that require base32 representation.

Key features: - I2P-compatible base32 alphabet (excludes confusing characters) - Consistent lowercase encoding for .b32.i2p domain compatibility - Error handling for invalid input data during decoding operations - High-performance encoding/decoding suitable for network operations

Common usage patterns:

encoded := base32.EncodeToString(binaryData)
decoded, err := base32.DecodeString(encodedString)

Package base32 implements utilities for encoding and decoding text using I2P's

alphabet

Package base32 implements utilities for encoding and decoding text using I2P's

alphabet

Usage

const I2PEncodeAlphabet = "abcdefghijklmnopqrstuvwxyz234567"

I2PEncodeAlphabet defines the base32 character set used throughout the I2P network. This alphabet follows RFC 3548 specifications but uses lowercase letters for consistency with I2P addressing conventions and .b32.i2p domain format requirements. The alphabet excludes confusing characters like 0, 1, 8, and 9 to prevent user errors.

var I2PEncoding *b32.Encoding = b32.NewEncoding(I2PEncodeAlphabet)

I2PEncoding provides the standard base32 encoder/decoder used across I2P components. This encoding instance is configured with the I2P-specific alphabet and is used for generating destination addresses, router identifiers, and other base32-encoded data within the I2P ecosystem. It ensures consistent encoding/decoding behavior.

func DecodeString
func DecodeString(data string) ([]byte, error)

DecodeString decodes a base32 string back to binary data using I2P's encoding alphabet. It converts I2P-compatible base32 strings back to their original byte representation. Returns an error if the input contains invalid base32 characters or padding. Example: DecodeString("jbswy3dp") returns []byte{72, 101, 108, 108, 111}, nil

func EncodeToString
func EncodeToString(data []byte) string

EncodeToString encodes binary data to a base32 string using I2P's encoding alphabet. It converts arbitrary byte data into a human-readable base32 string representation using the I2P-specific lowercase alphabet defined in RFC 3548. Example: EncodeToString([]byte{72, 101, 108, 108, 111}) returns "jbswy3dp"

base32

github.com/go-i2p/common/base32

go-i2p template file

Documentation

Overview

Package base32 implements utilities for encoding and decoding text using I2P's alphabet.

This package provides I2P-specific base32 encoding/decoding functionality using RFC 3548 with lowercase characters as specified by the I2P protocol. The implementation supports encoding binary data to human-readable strings for I2P destinations, router identifiers, and other network components that require base32 representation.

Key features: - I2P-compatible base32 alphabet (excludes confusing characters) - Consistent lowercase encoding for .b32.i2p domain compatibility - Error handling for invalid input data during decoding operations - High-performance encoding/decoding suitable for network operations

Common usage patterns:

encoded := base32.EncodeToString(binaryData)
decoded, err := base32.DecodeString(encodedString)

Package base32 implements utilities for encoding and decoding text using I2P's alphabet

Package base32 error definitions

Package base32 implements utilities for encoding and decoding text using I2P's alphabet

Index

Constants

View Source
const I2PEncodeAlphabet = "abcdefghijklmnopqrstuvwxyz234567"

I2PEncodeAlphabet defines the base32 character set used throughout the I2P network. This alphabet follows RFC 3548 specifications but uses lowercase letters for consistency with I2P addressing conventions and .b32.i2p domain format requirements. The alphabet excludes confusing characters like 0, 1, 8, and 9 to prevent user errors.

View Source
const MAX_ENCODE_SIZE = 10 * 1024 * 1024 // 10 MB

MAX_ENCODE_SIZE defines the maximum number of bytes that can be base32 encoded in a single operation. This limit prevents excessive memory allocation and ensures reasonable processing times. The limit of 10MB is sufficient for all I2P protocol needs including router infos, destinations, and lease sets, while preventing potential DoS through memory exhaustion.

Variables

View Source
var (
	// ErrEmptyData is returned when attempting to encode empty data.
	// Empty data cannot be meaningfully encoded and likely indicates a programming error.
	ErrEmptyData = errors.New("cannot encode empty data")

	// ErrDataTooLarge is returned when data exceeds MAX_ENCODE_SIZE.
	// This prevents excessive memory allocation and potential DoS attacks.
	ErrDataTooLarge = errors.New("data exceeds maximum encodable size")
)

I2PEncoding provides the standard base32 encoder/decoder used across I2P components. This encoding instance is configured with the I2P-specific alphabet and is used for generating destination addresses, router identifiers, and other base32-encoded data within the I2P ecosystem. It ensures consistent encoding/decoding behavior.

Functions

func DecodeString

func DecodeString(data string) ([]byte, error)

DecodeString decodes a base32 string back to binary data using I2P's encoding alphabet. It converts I2P-compatible base32 strings back to their original byte representation. Returns an error if the input contains invalid base32 characters or padding. Example: DecodeString("jbswy3dp") returns []byte{72, 101, 108, 108, 111}, nil

func EncodeToString

func EncodeToString(data []byte) string

EncodeToString encodes binary data to a base32 string using I2P's encoding alphabet. It converts arbitrary byte data into a human-readable base32 string representation using the I2P-specific lowercase alphabet defined in RFC 3548. Example: EncodeToString([]byte{72, 101, 108, 108, 111}) returns "jbswy3dp"

func EncodeToStringSafe added in v0.1.0

func EncodeToStringSafe(data []byte) (string, error)

EncodeToStringSafe encodes binary data to a base32 string with input validation. Unlike EncodeToString, this function validates the input data size to prevent excessive memory allocation and potential DoS attacks. Use this function when encoding untrusted or user-provided data. Returns an error if data is empty or exceeds MAX_ENCODE_SIZE. Example: EncodeToStringSafe([]byte{72, 101, 108, 108, 111}) returns "jbswy3dp", nil

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL