encoding

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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, base64_std
base64url→ b64url, base64url, base64-url, base64_url, urlsafe, url-safe

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