nonce

package
v0.0.0-...-16aca47 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: GPL-2.0, GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a concurrency-safe nonce store with TTL-based expiry. It is used to detect and reject replayed beacon nonces.

func NewBoundedCache

func NewBoundedCache(ttl time.Duration, maxEntries int) *Cache

NewBoundedCache creates a nonce cache with an explicit hard entry cap.

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache creates a Cache where nonces expire after ttl.

func (*Cache) Add

func (c *Cache) Add(n []byte)

Add records a nonce. Call only after Seen returns false.

func (*Cache) Seen

func (c *Cache) Seen(n []byte) bool

Seen reports whether n has been added and has not yet expired.

func (*Cache) SeenOrAdd

func (c *Cache) SeenOrAdd(n []byte) bool

SeenOrAdd atomically checks whether n was already seen and, if not, records it. Returns true if n was already present (replay; caller should reject). Returns false if n was new (caller may proceed); the nonce is recorded under the same lock.

Callers must use SeenOrAdd rather than the separate Seen+Add pair to prevent a TOCTOU race where two concurrent requests carrying the same nonce both pass Seen before either calls Add.

Jump to

Keyboard shortcuts

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