store

package
v0.0.0-...-0baee41 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSchema

func CreateSchema(db *sql.DB) error

func MustCreateSchema

func MustCreateSchema(db *sql.DB)

Types

type Database

type Database interface {
	Exec(query string, args ...any) (sql.Result, error)
	QueryRow(query string, args ...any) *sql.Row
}

type PrivateKey

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

func NewPrivateKey

func NewPrivateKey(db Database) *PrivateKey

func (PrivateKey) CreatePrivateKey

func (svc PrivateKey) CreatePrivateKey() (int64, error)

CreatePrivateKey creates a new private key in the database and returns its ID.

func (PrivateKey) FindPrivateKey

func (svc PrivateKey) FindPrivateKey(id int64) (*rsa.PrivateKey, error)

FindPrivateKey returns the private key with the given ID.

func (PrivateKey) Lease

func (svc PrivateKey) Lease(recordIDs []int64) error

Lease finds an available private key and leases it for the given record IDs. Must be used with a transaction to prevent races.

func (PrivateKey) ResetLeases

func (svc PrivateKey) ResetLeases() error

ResetLeases resets the leases on all private keys which have signed all associated records. TODO: Return how many leases were reset.

type Record

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

func NewRecord

func NewRecord(db *sql.DB) *Record

func (Record) CreateRecord

func (svc Record) CreateRecord(data string) (int64, error)

func (Record) FindAvailableRecords

func (svc Record) FindAvailableRecords(limit int) ([]int64, error)

FindAvailableRecords returns a list of record IDs that have been marked for signatures.

type Signature

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

func NewSignature

func NewSignature(db *sql.DB) *Signature

func (Signature) CreateSignature

func (svc Signature) CreateSignature(recordID, privKeyID int64) (int64, error)

CreateSignature creates a new signature for the given record and private key. It does not set the value of the signature, which must be updated later.

func (Signature) EmptySignature

func (svc Signature) EmptySignature() (SignatureRow, error)

EmptySignature returns the first signature that has yet to be signed.

func (Signature) SignWithKey

func (svc Signature) SignWithKey(pkey *rsa.PrivateKey, sigID int64) error

SignWithKey signs the associated record with the given signature ID using the given private key.

type SignatureRow

type SignatureRow struct {
	ID        int64
	RecordID  int64
	PrivKeyID int64
}

Jump to

Keyboard shortcuts

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