nonce

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

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