Documentation
¶
Overview ¶
Package capability mints and verifies capability tokens: a token that is, for a few minutes, the right to one thing a service names in a grant of its own type, and nothing else.
A service hands one out as a link, so that a file reaches the machine that wants it without passing through whatever asked for it -- a model would have to repeat it byte for byte. The token is all the link's holder needs, which is why it says exactly what it grants and runs out soon.
A token is the grant and its expiry as JSON, base64url-encoded, then a dot and an HMAC-SHA256 of that, keyed with the service's key and prefixed with its domain, so that two services' tokens are never mistaken for each other's even should they ever share a key.
Index ¶
Constants ¶
const DefaultTtl = 10 * time.Minute
DefaultTtl is how long a token lasts: long enough to be used at once, short enough that one found later in a log or a transcript grants nothing.
const MinKeyBytes = 32
MinKeyBytes is the shortest key a signer takes.
Variables ¶
var ( // ErrMalformed is a token that is not one a signer could have made. ErrMalformed = errors.New("malformed token") // ErrBadSignature is a token whose signature is not the key's, in the signer's domain. ErrBadSignature = errors.New("bad signature") // ErrExpired is a token whose time has run out. ErrExpired = errors.New("expired token") )
Functions ¶
This section is empty.
Types ¶
type Signer ¶
type Signer[T any] struct { // contains filtered or unexported fields }
Signer mints and verifies tokens of grants of type T, with one key in one domain.
func NewSigner ¶
func NewSigner[T any](key []byte, domain string, ttl time.Duration, now func() time.Time) (*Signer[T], error)
NewSigner is a signer of the key, which is to be random and at least MinKeyBytes long, in the domain, which names the service and the use ("vvvp-google/download/v1"). A ttl of zero is DefaultTtl; a nil now is time.Now.