nonce

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB implements the Store interface using postgres as it's backend.

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

NewDB prepares a new DB instance for the given sql.DB.

func (*DB) Consume

func (db *DB) Consume(ctx context.Context, id [16]byte) (bool, error)

Consume will record the use of a nonce value.

An error is returned if it is not possible to validate the nonce value. Otherwise true/false is returned to indicate if the id is valid.

The first call to Consume for a given ID will return true, subsequent calls for the same ID will return false.

func (*DB) New

func (db *DB) New() (id [16]byte)

New will generate a new cryptographically random nonce value.

func (*DB) Shutdown

func (db *DB) Shutdown(ctx context.Context) error

Shutdown allows gracefully shutting down the nonce store.

type Store

type Store interface {
	New() [16]byte
	Consume(context.Context, [16]byte) (bool, error)
	Shutdown(context.Context) error
}

Store allows generating and consuming nonce values.

Jump to

Keyboard shortcuts

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