pairingcode

package
v0.27.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pairingcode generates and validates short, human-readable codes — the kind a person reads off one screen and types on another (device pairing, invitation links). Codes use a Crockford-style alphabet with the visually ambiguous characters removed.

Index

Constants

View Source
const (
	DeviceCodeLength = 8
	InviteCodeLength = 12
)

Canonical code lengths. Device pairing keeps 8 (~2^39, paired with a short TTL and per-IP rate limit); invitation codes use 12 (~2^59) because their link lives for days.

View Source
const Alphabet = "23456789ABCDEFGHJKMNPQRSTVWXYZ"

Alphabet is a Crockford-style alphabet with the visually ambiguous characters removed (no 0/O, 1/I/L, or U), so a human can read a code off one screen and type it on another without confusion. 30 characters.

Variables

This section is empty.

Functions

func IsValid

func IsValid(code string, length int) bool

IsValid reports whether code is a well-formed canonical code (right length, only alphabet characters). Callers should Normalize first.

func New

func New(length int) (string, error)

New returns a fresh canonical code of the given length: uppercase, no separator. It draws from crypto/rand with rejection sampling so every character is uniform (a plain byte%30 would bias the first 256%30 characters).

func Normalize

func Normalize(code string) string

Normalize canonicalizes a code as typed by a user: uppercased, with the display grouping (hyphens) and any stray spaces removed. It does not validate — pair it with IsValid.

Types

This section is empty.

Jump to

Keyboard shortcuts

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