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 ¶
- Variables
- func ArrayElements(value []byte, visit func(elem []byte) error) error
- func DecodeBase64URL(value string, maxEncodedBytes, maxDecodedBytes int) ([]byte, error)
- func ObjectMembers(data []byte, options JSONOptions, visit func(name, value []byte) error) error
- func Unquote(raw []byte) (string, bool)
- func ValidateJSON(data []byte, options JSONOptions) error
- type JSONOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidSize = errors.New("authn: invalid size") ErrInvalidEncoding = errors.New("authn: invalid encoding") ErrLimitExceeded = errors.New("authn: limit exceeded") )
var ( ErrMalformedJSON = errors.New("authn: malformed JSON") ErrDuplicateJSON = errors.New("authn: duplicate JSON member") )
Functions ¶
func ArrayElements ¶ added in v1.2.13
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 ¶
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
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 ¶
JSONOptions bounds a document: its size in bytes, how deeply values nest, and how many object members and array elements it holds in all.