authn

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package authn contains the bounded parsing primitives the jwt package shares. Protocol-specific algorithm and key policy does not belong in this package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSize     = errors.New("authn: invalid size")
	ErrInvalidEncoding = errors.New("authn: invalid encoding")
	ErrLimitExceeded   = errors.New("authn: limit exceeded")
)
View Source
var (
	ErrMalformedJSON = errors.New("authn: malformed JSON")
	ErrDuplicateJSON = errors.New("authn: duplicate JSON member")
)

Functions

func ArrayElements added in v1.2.13

func ArrayElements(value []byte, visit func(elem []byte) error) error

ArrayElements hands each element of value, which must be a JSON array that ValidateJSON or ObjectMembers has accepted, to visit as the bytes that spell it.

func DecodeBase64URL

func DecodeBase64URL(value string, maxEncodedBytes, maxDecodedBytes int) ([]byte, error)

DecodeBase64URL strictly decodes canonical, unpadded Base64url.

Canonicality used to be checked by re-encoding the result and comparing, which copied every segment twice more. DecodeString already rejects padding, wrong lengths, and bytes outside the alphabet, with two exceptions this function closes itself: it skips \r and \n instead of failing, and it accepts a final quantum whose unused low bits are not zero. The exhaustive test in this package holds the sum of these checks equal to the re-encoding oracle.

func ObjectMembers added in v1.2.13

func ObjectMembers(data []byte, options JSONOptions, visit func(name, value []byte) error) error

ObjectMembers validates data as ValidateJSON does, requires its value to be an object, and hands that object's members to visit in document order: the name decoded, the value as the bytes of the document that spell it. Each value has been validated before visit sees it. A nested object's members are not visited.

Both slices are views of data, except a name that had to be decoded, which is its own copy. A visitor that keeps the value keeps data alive.

func Unquote added in v1.2.13

func Unquote(raw []byte) (string, bool)

Unquote decodes a JSON string token, quotes included, that ValidateJSON or ObjectMembers has accepted. Escapes are resolved as encoding/json resolves them: a surrogate pair becomes one character, a lone surrogate and an invalid UTF-8 sequence become U+FFFD.

func ValidateJSON

func ValidateJSON(data []byte, options JSONOptions) error

ValidateJSON reports whether data is exactly one JSON value within options, with no member name repeated within any object. The grammar is RFC 8259's; a string may carry any bytes above the control range, which is what encoding/json accepts too.

This is a hand-written scanner rather than encoding/json's token stream, which boxed every token, kept a set of names per object, and so allocated some thirty times to validate a token's two small objects.

Types

type JSONOptions

type JSONOptions struct {
	MaxBytes   int
	MaxDepth   int
	MaxMembers int
}

JSONOptions bounds a document: its size in bytes, how deeply values nest, and how many object members and array elements it holds in all.

Jump to

Keyboard shortcuts

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