token

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package token makes and checks the signed tokens in links and addresses: confirm, unsubscribe, open, click and bounce. A token carries its purpose and a few integer IDs, authenticated with HMAC-SHA256, so handlers verify it without a lookup and nobody can forge or enumerate one.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid token")

ErrInvalid is returned for tokens that are malformed or not signed by us.

Functions

This section is empty.

Types

type Kind

type Kind byte

Kind is what a token authorizes.

const (
	Confirm Kind = 'c' // confirm membership: member ID
	Unsub   Kind = 'u' // unsubscribe: member ID, issue ID (0 outside issues)
	Open    Kind = 'o' // open pixel: outbound ID
	Click   Kind = 'k' // click: outbound ID, link index
	Bounce  Kind = 'b' // envelope sender (VERP): outbound ID
	Message Kind = 'm' // Message-ID: outbound ID; it identifies, never authorizes
	Form    Kind = 'f' // signup form render time: unix seconds
	Hook    Kind = 'h' // webhook URL: constant 1
)

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer signs and verifies tokens with one secret.

func New

func New(secret []byte) *Signer

New returns a Signer; the secret should be 32 random bytes.

func (*Signer) Make

func (s *Signer) Make(kind Kind, ids ...int64) string

Make encodes kind and ids into a URL- and local-part-safe token.

func (*Signer) Parse

func (s *Signer) Parse(kind Kind, tok string, n int) ([]int64, error)

Parse checks a token of the given kind and returns its ids.

Jump to

Keyboard shortcuts

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