encoding

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package encoding is a small translation layer over the stdlib encoders used across the Truestamp wire format: hex, base64 (standard, RFC 4648 §4) and base64url (RFC 4648 §5). "Binary" is a pass-through used as the counterpart to any textual encoding when bytes move through stdin/stdout.

The goal is a uniform behaviour across platforms for the `truestamp encode`, `truestamp decode`, and `truestamp convert` sub-commands so users do not have to shell out to `xxd`, `base64`, or similar tools whose flags differ between macOS, BSD, GNU coreutils, and Git-Bash.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyDecodeInput = errors.New("empty input")

ErrEmptyDecodeInput signals that decode was asked to decode nothing. Returned as an error so callers can surface a clear message; decoders would otherwise silently produce an empty output which hides bugs.

Functions

func AllNames

func AllNames() []string

AllNames returns the canonical names in display order.

func Decode

func Decode(enc Encoding, data []byte) ([]byte, error)

Decode interprets data as the given encoding and returns raw bytes. Tolerates a single trailing newline and any leading/trailing whitespace (common when piping from shells or editors). Rejects mixed/cross-encoding characters inside the payload.

func Encode

func Encode(enc Encoding, data []byte) ([]byte, error)

Encode renders raw bytes in the given encoding. Binary passes the bytes through unchanged.

Types

type Encoding

type Encoding int

Encoding enumerates the supported representations.

const (
	Binary Encoding = iota
	Hex
	Base64Std
	Base64URL
)

Supported encodings.

func Parse

func Parse(s string) (Encoding, error)

Parse looks up an Encoding by any accepted spelling (case-insensitive):

binary   → bin, binary, raw, bytes
hex      → hex, base16
base64   → b64, base64, base64std, base64-std
base64url→ b64url, base64url, base64-url, base64_url, urlsafe

func (Encoding) Name

func (e Encoding) Name() string

Name returns the canonical string form (used by --json output).

Jump to

Keyboard shortcuts

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