state

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package state defines transactional, expiring byte records for protocol state.

Design

Token exchange, certificate associations, revocation and quotas need atomic updates without importing database drivers. Memory supports a single process, while server/statestore provides shared SQL persistence. Transactions expose store time so expiry and quota decisions can use a consistent clock. Callers own serialization, namespaces, key selection and record lifetimes. In-memory state is lost on restart.

References

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("state: record not found")
	ErrInvalid  = errors.New("state: invalid key or transaction")
)

Functions

func ValidKey

func ValidKey(k string) bool

ValidKey permits printable ASCII keys of at most 255 bytes across all backends.

Types

type Memory

type Memory struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

Memory is a serializable store. Now may be set before use for deterministic tests.

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty store.

func (*Memory) Get

func (m *Memory) Get(ctx context.Context, key string) (Record, error)

Get implements Reader.

func (*Memory) List

func (m *Memory) List(ctx context.Context, prefix, after string, limit int) ([]Record, error)

List implements Reader.

func (*Memory) Prune

func (m *Memory) Prune(ctx context.Context, limit int) (int, error)

Prune implements Store.

func (*Memory) Update

func (m *Memory) Update(ctx context.Context, keys []string, fn func(Tx) error) error

Update implements Store. A private write set makes callback failures atomic.

type Reader

type Reader interface {
	Get(context.Context, string) (Record, error)
	// List returns up to limit records in key order, strictly after after.
	List(ctx context.Context, prefix, after string, limit int) ([]Record, error)
}

Reader reads records, including expired ones; protocol callers validate expiry.

type Record

type Record struct {
	Key       string
	Value     []byte
	ExpiresAt time.Time
}

Record is opaque state. A zero ExpiresAt means retain until explicitly deleted.

type Store

type Store interface {
	Reader
	Update(ctx context.Context, keys []string, fn func(Tx) error) error
	// Prune deletes at most limit expired records. It never deletes immortal data.
	Prune(ctx context.Context, limit int) (int, error)
}

Store commits all writes in a callback or none. Updates sharing any lock key serialize; callers must use the same lock keys for every writer of a record. Keys may designate a whole logical group (for example an issuer's CRL).

type Tx

type Tx interface {
	Reader
	Now() time.Time
	Put(context.Context, Record) error
	Delete(context.Context, string) error
}

Tx is valid only during Update. Now is authoritative store time sampled after acquiring locks. A callback must not re-enter the Store or retain its Tx.

Jump to

Keyboard shortcuts

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