store

package module
v0.0.0-...-f198957 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package store provides interfaces and cryptographic primitives for Store implementations.

Index

Constants

View Source
const (
	DefaultArgonKeyLength  = 128
	DefaultArgonTimeCost   = 1
	DefaultArgonMemoryCost = 64 * 1024 // recommended by x/crypto/argon2
	DefaultArgonThreads    = 4
)
View Source
const DefaultTableName = `kidwords_paper_keys`
View Source
const InstallPostgresTable = `` /* 232-byte string literal not displayed */
View Source
const InstallSQLiteTable = `` /* 208-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgonHash

type ArgonHash struct {
	Type            string
	Version         uint8
	TimeCost        uint32
	MemoryCost      uint32
	ParallelThreads uint8
	Salt            []byte
	Secret          []byte
}

ArgonHash is a parameterized salted hash used for storing keys.

func NewArgonHash

func NewArgonHash(key []byte) (*ArgonHash, error)

NewArgonHash creates an Argon2id hash using default parameters.

func NewCustomArgonHash

func NewCustomArgonHash(
	key []byte,
	timeCost uint32,
	memoryCost uint32,
	parallelThreads uint8,
) (*ArgonHash, error)

NewCustomArgonHash creates an Argon hash.

func ParseArgonHash

func ParseArgonHash(h string) (result *ArgonHash, err error)

ParseArgonHash constructs an ArgonHash from a serialized string following the format `$<type>$v=<version>$m=<memory>,t=<time>,p=<parallel>$<salt>$<secret>`.

func (*ArgonHash) Match

func (a *ArgonHash) Match(key []byte) (bool, error)

Match hashes the given key using ArgonHash parameters and compares the result with [ArgonHash.Secret].

func (*ArgonHash) String

func (a *ArgonHash) String() string

String serializes the ArgonHash using format `$<type>$v=<version>$m=<memory>,t=<time>,p=<parallel>$<salt>$<secret>`.

type Authenticator

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

Authenticator simplifies low level Store operations and secures them with reasonable defaults. Use it to verify that a particular owner knows one of the [PaperKey]s associated with them.

func NewAuthenticator

func NewAuthenticator(using Store, desiredPaperKeyByteCount int64) (*Authenticator, error)

func (*Authenticator) AddPaperKey

func (a *Authenticator) AddPaperKey(
	ctx context.Context,
	keyOwner string,
	keyName string,
) (key *PaperKey, err error)

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(
	ctx context.Context,
	keyOwner string,
	key string,
) (bool, error)

func (*Authenticator) ListPaperKeys

func (a *Authenticator) ListPaperKeys(
	ctx context.Context,
	keyOwner string,
) ([]*PaperKey, error)

func (*Authenticator) RemoveOwner

func (a *Authenticator) RemoveOwner(
	ctx context.Context,
	keyOwner string,
) (err error)

func (*Authenticator) RemovePaperKey

func (a *Authenticator) RemovePaperKey(
	ctx context.Context,
	ID string,
	keyOwner string,
) (err error)

type Option

type Option func(*options) error

func WithGuaranteedTable

func WithGuaranteedTable() Option

func WithTableName

func WithTableName(name string) Option

type PaperKey

type PaperKey struct {
	ID         string
	Owner      string
	Name       string
	SaltedHash string
	Created    time.Time
}

func (*PaperKey) LogValue

func (p *PaperKey) LogValue() slog.Value

type PostgresStore

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

func NewPostgresStore

func NewPostgresStore(database *sql.DB, withOptions ...Option) (s *PostgresStore, err error)

func (*PostgresStore) Create

func (s *PostgresStore) Create(ctx context.Context, p *PaperKey) error

func (*PostgresStore) Delete

func (s *PostgresStore) Delete(ctx context.Context, ID string) error

func (*PostgresStore) DeleteByOwner

func (s *PostgresStore) DeleteByOwner(ctx context.Context, owner string) error

func (*PostgresStore) RetrieveAll

func (s *PostgresStore) RetrieveAll(
	ctx context.Context,
	owner string,
) (result []*PaperKey, err error)

type SQLiteStore

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

func NewSQLiteStore

func NewSQLiteStore(database *sql.DB, withOptions ...Option) (s *SQLiteStore, err error)

func (*SQLiteStore) Create

func (s *SQLiteStore) Create(ctx context.Context, p *PaperKey) error

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, ID string) error

func (*SQLiteStore) DeleteByOwner

func (s *SQLiteStore) DeleteByOwner(ctx context.Context, owner string) error

func (*SQLiteStore) RetrieveAll

func (s *SQLiteStore) RetrieveAll(
	ctx context.Context,
	owner string,
) (result []*PaperKey, err error)

type Store

type Store interface {
	Create(ctx context.Context, p *PaperKey) error
	RetrieveAll(ctx context.Context, owner string) ([]*PaperKey, error)
	Delete(ctx context.Context, id string) error
	DeleteByOwner(ctx context.Context, owner string) error
}

Directories

Path Synopsis
test module

Jump to

Keyboard shortcuts

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