keydb

package
v0.0.0-...-097916a Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCryptorVersion = fmt.Errorf("Cryptor version does not match")
View Source
var ErrDBVersion = fmt.Errorf("DB version does not match")

Functions

This section is empty.

Types

type Cryptor

type Cryptor interface {
	Decrypt(*DBKey) (*knox.Key, error)
	Encrypt(*knox.Key) (*DBKey, error)
	EncryptVersion(*knox.Key, *knox.KeyVersion) (*EncKeyVersion, error)
}

Cryptor is an interface for converting a knox Key to a DB Key

func NewAESGCMCryptor

func NewAESGCMCryptor(version byte, keyData []byte) Cryptor

NewAESGCMCryptor creates a Cryptor that performs AES GCM AEAD encryption on key data.

type DB

type DB interface {
	// Get returns the key specified by the ID.
	Get(id string) (*DBKey, error)
	// GetAll returns all of the keys in the database.
	GetAll() ([]DBKey, error)

	// Update makes an update to DBKey indexed by its ID.
	// It will fail if the key has been changed since the specified version.
	Update(key *DBKey) error
	// Add adds the key(s) to the DB (it will fail if the key id exists).
	Add(keys ...*DBKey) error
	// Remove permanently removes the key specified by the ID.
	Remove(id string) error
}

DB is the underlying database connection that KeyDB uses for all of its operations.

This interface should not contain any business logic and should only deal with formatting and database specific logic.

func NewPostgreSQLDB

func NewPostgreSQLDB(sqlDB *sql.DB) (DB, error)

NewPostgreSQLDB will create a SQLDB with the necessary statements for using postgres.

func NewSQLDB

func NewSQLDB(sqlDB *sql.DB) (DB, error)

NewSQLDB creates a table and prepared statements suitable for mysql and sqlite databases.

func NewTempDB

func NewTempDB() DB

NewTempDB creates a new TempDB with no data.

type DBKey

type DBKey struct {
	ID          string          `json:"id"`
	ACL         knox.ACL        `json:"acl"`
	VersionList []EncKeyVersion `json:"versions"`
	VersionHash string          `json:"hash"`
	// The version should be set by the db provider and is not part of the data.
	DBVersion int64 `json:"-"`
}

DBKey is a struct for the json serialization of keys in the database.

func (*DBKey) Copy

func (k *DBKey) Copy() *DBKey

Copy provides a deep copy of database keys so that VersionLists can be edited in a copy.

type EncKeyVersion

type EncKeyVersion struct {
	ID             uint64             `json:"id"`
	EncData        []byte             `json:"data"`
	Status         knox.VersionStatus `json:"status"`
	CreationTime   int64              `json:"ts"`
	CryptoMetadata []byte             `json:"crypt"`
}

EncKeyVersion is a struct for encrypting key data

type EtcdConnector

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

func NewEtcdConnector

func NewEtcdConnector(endpoints []string, initialTimeout, dialTimeout, contextTimeout time.Duration) *EtcdConnector

func (*EtcdConnector) Add

func (connector *EtcdConnector) Add(keys ...*DBKey) error

func (*EtcdConnector) Close

func (connector *EtcdConnector) Close()

func (*EtcdConnector) Get

func (connector *EtcdConnector) Get(id string) (*DBKey, error)

func (*EtcdConnector) GetAll

func (connector *EtcdConnector) GetAll() ([]DBKey, error)

func (*EtcdConnector) Remove

func (connector *EtcdConnector) Remove(id string) error

func (*EtcdConnector) Update

func (connector *EtcdConnector) Update(key *DBKey) error

type SQLDB

type SQLDB struct {
	UpdateStmt *sql.Stmt
	AddStmt    *sql.Stmt
	RemoveStmt *sql.Stmt
	// contains filtered or unexported fields
}

SQLDB provides a generic way to use SQL providers as Knox DBs.

func (*SQLDB) Add

func (db *SQLDB) Add(keys ...*DBKey) error

Add adds the key version (it will fail if the key id exists).

func (*SQLDB) Get

func (db *SQLDB) Get(id string) (*DBKey, error)

Get will return the key given its key ID.

func (*SQLDB) GetAll

func (db *SQLDB) GetAll() ([]DBKey, error)

GetAll returns all of the keys in the database.

func (*SQLDB) Remove

func (db *SQLDB) Remove(id string) error

Remove permanently removes the key specified by the ID.

func (*SQLDB) Update

func (db *SQLDB) Update(key *DBKey) error

Update makes an update to DBKey indexed by its ID. It will fail if the key has been changed since the specified version.

type TempDB

type TempDB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TempDB is an in memory DB that does no replication across servers and starts out fresh everytime. It is written for testing and simple dev work.

func (*TempDB) Add

func (db *TempDB) Add(keys ...*DBKey) error

Add adds the key(s) to the DB (it will fail if the key id exists).

func (*TempDB) Get

func (db *TempDB) Get(id string) (*DBKey, error)

Get gets stored db key from TempDB.

func (*TempDB) GetAll

func (db *TempDB) GetAll() ([]DBKey, error)

GetAll gets all keys from TempDB.

func (*TempDB) Remove

func (db *TempDB) Remove(id string) error

Remove will remove the key id from the database.

func (*TempDB) SetError

func (db *TempDB) SetError(err error)

SetError is used to set the error the TempDB for testing purposes.

func (*TempDB) Update

func (db *TempDB) Update(key *DBKey) error

Update looks for an existing key and updates the key in the database.

Jump to

Keyboard shortcuts

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