nonce

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReused = errors.New("nonce reuse detected")

Functions

func New

func New() ([]byte, error)

Types

type MapVerifier

type MapVerifier struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MapVerifier keeps an in-memory map of nonces that it has seen. The map is pruned of expired tokens periodically. This is NOT SAFE for use in a distributed environment.

func NewMapVerifier

func NewMapVerifier(pruneEvery time.Duration) *MapVerifier

NewMapVerifier creates a new nonce verifier that prunes expired nonces at the given cadence.

func (*MapVerifier) Verify

func (m *MapVerifier) Verify(nonce []byte, expires time.Time) error

Verify that the nonce has not been seen before, and save it in the map so that future calls with this nonce fail.

type Verifier

type Verifier interface {
	// Verify that the given nonce has not been seen. The expiry time of the associated token
	// is given so that the server may know when it is safe to stop tracking this nonce.
	Verify(nonce []byte, expires time.Time) error
}

Jump to

Keyboard shortcuts

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