Documentation
¶
Overview ¶
Package keys holds signing and encryption keys for access tokens.
Every Key is pinned to one algorithm. A Provider exposes the active key (read on every issue, so rotation is immediate) and the keys still accepted for verification. MemoryProvider is an in-process implementation; back Provider with a KMS or Vault for multiple instances.
Index ¶
Constants ¶
const MinHMACKeySize = 32
MinHMACKeySize is the minimum HMAC secret length (256 bits).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alg ¶
type Alg string
Alg names the algorithm a key is pinned to. A key is only ever used with its own algorithm; the algorithm named inside a token is never trusted.
type Key ¶
type Key struct {
ID string // logical key ID (kid); must be unique per provider
Alg Alg // pinned algorithm; token formats may define their own values
Secret []byte // symmetric key material (HS256, PASETO local)
PrivateKey ed25519.PrivateKey // EdDSA signing key
PublicKey ed25519.PublicKey // EdDSA verification key
}
Key represents a cryptographic key usable for issuing or verifying tokens.
func (Key) ValidateForJWT ¶
ValidateForJWT reports whether k is usable for JWT signing (sign=true) or verification (sign=false).
type MemoryProvider ¶
type MemoryProvider struct {
// contains filtered or unexported fields
}
MemoryProvider is an in-memory rotating key provider.
NOT for distributed systems (yet). Perfect for monolith / MVP.
func NewMemoryProvider ¶
func NewMemoryProvider(initial Key) *MemoryProvider
NewMemoryProvider creates a key provider with an initial active key.
func (*MemoryProvider) ActiveKey ¶
func (p *MemoryProvider) ActiveKey() Key
ActiveKey returns the current active key.
func (*MemoryProvider) Prune ¶
func (p *MemoryProvider) Prune(maxOld int)
Prune removes old keys beyond retention count.
Call this AFTER rotation window expires.
func (*MemoryProvider) Rotate ¶
func (p *MemoryProvider) Rotate(newKey Key) error
Rotate promotes a new key to active.
Old active key is retained for verification. The new key ID must be non-empty and must not match any key already held.
func (*MemoryProvider) VerificationKeys ¶
func (p *MemoryProvider) VerificationKeys() []Key
VerificationKeys returns all keys valid for verification.
Order matters:
- active key first (fast path)
- then older keys
type Provider ¶
Provider exposes active and historical keys.
Contract:
- ActiveKey() is used ONLY for issuing tokens, and is read on every issue so that rotation takes effect immediately
- VerificationKeys() is used for verification
- VerificationKeys MUST include ActiveKey
- implementations must be safe for concurrent use