nonceprovider

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package nonceprovider contains implementations of the login nonce store.

Index

Constants

This section is empty.

Variables

View Source
var ErrStoreFull = errors.New("nonce store is at capacity")

ErrStoreFull is returned by Issue when the store is at capacity and no expired entries can be reclaimed. It signals transient overload, not a client error.

Functions

This section is empty.

Types

type InMemory

type InMemory struct {
	// contains filtered or unexported fields
}

InMemory is an in-process nonce store suitable for a single api-server replica. Nonces are keyed by the requesting address so a given address holds at most one live nonce. Nonces are short-lived, so losing them on restart is harmless; run more than one replica and this must be replaced with a shared (e.g. Postgres) store.

func NewInMemory

func NewInMemory(ttl time.Duration) *InMemory

NewInMemory creates an InMemory nonce store whose nonces expire after ttl.

func (*InMemory) Consume

func (s *InMemory) Consume(nonce string) bool

Consume removes the nonce and reports whether it was live at the moment of use.

func (*InMemory) Issue

func (s *InMemory) Issue(address string) (string, error)

Issue returns a nonce for address. If the address already holds a live nonce it is returned unchanged, so repeat requests (retries, an attacker replaying the same address) do not grow the store. Otherwise a fresh nonce is minted. It purges expired entries on a fixed cadence and, when the store is full of live entries, returns ErrStoreFull instead of evicting another address's live nonce.

Jump to

Keyboard shortcuts

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