kv

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataPWHashSalt   = "pwhash:salt"
	MetadataPWHashTime   = "pwhash:time"
	MetadataPWHashMem    = "pwhash:mem"
	MetadataVersion      = "version"
	MetadataKeyCtlName   = "keyctl:name"
	MetadataVerification = "verify:verify"
)
View Source
const (
	MinSupportedVersion = 0
	MaxSupportedVersion = 0
	Version             = 0
)
View Source
const (
	DefaultArgonTimeParam uint32 = 16
	DefaultArgonMemParam  uint32 = 2048 * 1024 // 2GiB

	MinArgonTimeParam uint32 = 1
	MinArgonMemParam  uint32 = 1024 //1MiB

	LowArgonTimeParam uint32 = 8
	LowArgonMemParam  uint32 = 1024 * 1024 //1GiB

	HighArgonTimeParam uint32 = 24
	HighArgonMemParam  uint32 = 4096 * 1024 // 4GiB
)
View Source
const BlockSize = 16
View Source
const EncryptionKeySize = 64
View Source
const ItemOverheadBytes = 8 + 4
View Source
const NonceSize = 24
View Source
const SaltSize = 32
View Source
const (
	VerificationMessage = "The quick brown fox jumps over the lazy dog. Sphinx of black quartz, judge my vow."
)

Variables

View Source
var ErrNotFound = fmt.Errorf("requested value not found")

Functions

func GetMeta

func GetMeta[T MetaTypes](tx BackendTxn, key []byte) (T, error)

func NewSalt

func NewSalt(n int) ([]byte, error)

func SetMeta

func SetMeta[T MetaTypes](tx BackendTxn, key []byte, value T) error

func SupportedVersion

func SupportedVersion(version int) bool

Types

type ArgonParams

type ArgonParams struct {
	Time   uint32
	Memory uint32
}

func ArgonDefault

func ArgonDefault() ArgonParams

func ArgonHigh

func ArgonHigh() ArgonParams

func ArgonLow

func ArgonLow() ArgonParams

func (ArgonParams) Validate

func (a ArgonParams) Validate() error

type Backend

type Backend interface {
	Txn(func(BackendTxn) error) error

	Close()
}

func NewBackend

func NewBackend(path string) (Backend, error)

type BackendTxn

type BackendTxn interface {
	Get(bucket Bucket, key []byte) (value []byte, err error)
	Set(bucket Bucket, key []byte, value []byte) error
	Delete(bucket Bucket, key []byte) error
	Iterate(bucket Bucket, fn func(key, value []byte) error) error
}

type Bucket

type Bucket string
const (
	BucketMetadata Bucket = "metadata"
	BucketStore    Bucket = "store"
)

func (Bucket) Bytes

func (b Bucket) Bytes() []byte

type Closer

type Closer interface {
	Close(Backend, Crypto) error
}

func FallbackCloser

func FallbackCloser(closers ...Closer) Closer

func KeyCtlCloser

func KeyCtlCloser(exp time.Duration) Closer

type CloserFn

type CloserFn func(Backend, Crypto) error

func (CloserFn) Close

func (fn CloserFn) Close(b Backend, crypt Crypto) error

type Crypto

type Crypto interface {
	HMAC(data []byte) ([]byte, error)
	Encrypt(data []byte) ([]byte, error)
	Decrypt(cipher []byte) ([]byte, error)

	Close()
	// contains filtered or unexported methods
}

func PasswordHash

func PasswordHash(password, salt []byte, params ArgonParams) (Crypto, error)

type EncryptionKey

type EncryptionKey [EncryptionKeySize]byte

type Item

type Item interface {
	Key() []byte
	Value() []byte
	Timestamp() time.Time
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

func NewItem

func NewItem(key, value []byte) Item

type KV

type KV interface {
	Store
	Close() error
}

func New

func New(path string, keygen KeyGen, closer Closer) (KV, error)

func Open

func Open(path string, unlocker Unlocker, closer Closer) (KV, error)

type KeyGen

type KeyGen interface {
	KeyGen(Backend) (Crypto, error)
}

func PasswordKeyGen

func PasswordKeyGen(fetcher func() ([]byte, error), params ArgonParams) KeyGen

type KeyGenFn

type KeyGenFn func(Backend) (Crypto, error)

func (KeyGenFn) KeyGen

func (fn KeyGenFn) KeyGen(b Backend) (Crypto, error)

type MetaTypes

type MetaTypes interface {
	int64 | uint64 | float64 | bool | time.Time | time.Duration | string | []byte
}

Metadata getter helpers

type Nonce

type Nonce [NonceSize]byte

type Store

type Store interface {
	Txn(func(StoreTxn) error) error
}

type StoreTxn

type StoreTxn interface {
	Get(key []byte) (Item, error)
	Set(item Item) error
	Delete(key []byte) error
	Iterate(prefix []byte, fn func(item Item) error) error
}

type Unlocker

type Unlocker interface {
	Unlock(Backend) (Crypto, error)
}

func FallbackUnlocker

func FallbackUnlocker(unlockers ...Unlocker) Unlocker

func KeyCtlUnlocker

func KeyCtlUnlocker() Unlocker

func PasswordUnlocker

func PasswordUnlocker(fetcher func() ([]byte, error)) Unlocker

type UnlockerFn

type UnlockerFn func(Backend) (Crypto, error)

func (UnlockerFn) Unlock

func (fn UnlockerFn) Unlock(backend Backend) (Crypto, error)

Jump to

Keyboard shortcuts

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