db

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BucketConfig = []byte("Config")
View Source
var ErrAlreadyOpen = errors.Conflict.With("database is already open")
View Source
var ErrDatabaseAlreadyEncrypted = errors.BadRequest.With("database already encrypted")
View Source
var ErrInvalidPassword = errors.BadPassword.With("invalid password")
View Source
var ErrMalformedEncryptedDatabase = errors.InternalError.With("malformed encrypted database")
View Source
var ErrNoBucket = errors.NotFound.With("bucket not defined")
View Source
var ErrNotFound = errors.NotFound.With("key not found")
View Source
var ErrNotOpen = errors.BadRequest.With("database is not open")

Functions

func CheckSymKey added in v0.6.0

func CheckSymKey(key []byte) error

func DeriveSymKey added in v0.6.0

func DeriveSymKey(password, salt []byte) ([]byte, error)

func Magic

func Magic(raw DB) error

func PutMagic

func PutMagic(raw DB) error

func SymDecrypt added in v0.6.0

func SymDecrypt(ciphertext []byte, key []byte) ([]byte, error)

func SymEncrypt added in v0.6.0

func SymEncrypt(plaintext []byte, key []byte) ([]byte, error)

Types

type BoltDB

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

func OpenBolt

func OpenBolt(filename string) (*BoltDB, error)

func (*BoltDB) Close

func (b *BoltDB) Close() error

Close the database

func (*BoltDB) Delete

func (b *BoltDB) Delete(bucket []byte, key []byte) error

Delete will remove a key/value pair from the bucket

func (*BoltDB) DeleteBucket

func (b *BoltDB) DeleteBucket(bucket []byte) error

DeleteBucket will delete all key/value pairs from a bucket

func (*BoltDB) ForEachBucket

func (b *BoltDB) ForEachBucket(fn func(*Bucket) error) error

func (*BoltDB) Get

func (b *BoltDB) Get(bucket []byte, key []byte) (value []byte, err error)

Get will get an entry in the database given a bucket and key

func (*BoltDB) GetBucket

func (b *BoltDB) GetBucket(bucket []byte) (buck *Bucket, err error)

GetBucket will return the contents of a bucket

func (*BoltDB) Name

func (b *BoltDB) Name() string

func (*BoltDB) Put

func (b *BoltDB) Put(bucket []byte, key []byte, value []byte) error

type Bucket

type Bucket struct {
	Name         string
	KeyValueList []KeyValue //KeyValueList contains the key/value data for the entry
	// contains filtered or unexported fields
}

Bucket is the structure to store the key/value data and a reference map to pull it.

func NewBucket

func NewBucket() *Bucket

NewBucket creates a new instance of the bucket and initializes the map

func (*Bucket) Copy added in v0.6.3

func (b *Bucket) Copy() *Bucket

func (*Bucket) Delete

func (b *Bucket) Delete(key []byte) (err error)

Delete will remove the value given a key

func (*Bucket) Get

func (b *Bucket) Get(key []byte) (value []byte)

Get will retrieve the value given a key

func (*Bucket) Put

func (b *Bucket) Put(k []byte, v []byte)

Put will store the key / value in the bucket

type DB

type DB interface {
	Close() error                                            // Returns an error if the close fails
	Name() string                                            // returns the database filename if applicable
	Get(bucket []byte, key []byte) (value []byte, err error) // Get key from database (may further decrypt data if applicable), returns ErrNotFound if the key is not found
	Put(bucket []byte, key []byte, value []byte) error       // Put the value in the database (may further encrypt data if applicable), throws an error if fails
	GetBucket(bucket []byte) (*Bucket, error)                // GetBucket retrieves all the data contained within a bucket
	Delete(bucket []byte, key []byte) error                  // Delete will remove a key/value pair from the bucket
	DeleteBucket(bucket []byte) error                        // DeleteBucket will delete all key/value pairs from a bucket
}

DB defines the interface functions to access the database

type Encrypted

type Encrypted interface {
	DB
	Raw() DB        // Raw returns the underlying database
	IsLocked() bool //
	Lock()          // Lock the database

	// UnlockFor unlocks the encrypter and returns the time at which it will be
	// locked again. If the caller specifies a non-zero deadline, the encrypter
	// must set a deadline no later than that, though the encrypter may choose
	// to use an earlier deadline than the one requested. If the caller does not
	// specify a deadline (passes the zero value), the encrypter may still set a
	// deadline. The encrypter must return the deadline if one is set, or the
	// zero value otherwise.
	UnlockFor([]byte, time.Duration) (time.Time, error)
}

type FakeEncrypted

type FakeEncrypted struct {
	DB
}

FakeEncrypted implements Encrypted without actually encrypting anything.

func (*FakeEncrypted) IsLocked

func (e *FakeEncrypted) IsLocked() bool

func (*FakeEncrypted) Lock

func (e *FakeEncrypted) Lock()

func (*FakeEncrypted) Raw

func (e *FakeEncrypted) Raw() DB

func (*FakeEncrypted) UnlockFor

func (e *FakeEncrypted) UnlockFor(passphrase []byte, duration time.Duration) (dl time.Time, err error)

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte
}

KeyValue holds the key/value data for the entry

type MemoryDB

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

MemoryDB holds the main map of buckets for the in-memory database

func (*MemoryDB) Close

func (b *MemoryDB) Close() error

Close clears out the data and uninitializes the MemoryDB

func (*MemoryDB) Delete

func (b *MemoryDB) Delete(bucket []byte, key []byte) (err error)

Delete will remove a key/value pair from the bucket

func (*MemoryDB) DeleteBucket

func (b *MemoryDB) DeleteBucket(bucket []byte) error

DeleteBucket will delete all key/value pairs from a bucket

func (*MemoryDB) Get

func (b *MemoryDB) Get(bucket []byte, key []byte) (value []byte, err error)

func (*MemoryDB) GetBucket

func (b *MemoryDB) GetBucket(bucket []byte) (buck *Bucket, err error)

GetBucket will return the contents of a bucket

func (*MemoryDB) GetRaw

func (b *MemoryDB) GetRaw(bucket []byte, key []byte) (value []byte, err error)

Get will get an entry in the database given a bucket and key

func (*MemoryDB) IsLocked

func (b *MemoryDB) IsLocked() bool

func (*MemoryDB) Lock

func (b *MemoryDB) Lock()

func (*MemoryDB) Name

func (b *MemoryDB) Name() string

func (*MemoryDB) Put

func (b *MemoryDB) Put(bucket []byte, key []byte, value []byte) error

Put will write data to a given bucket using the key

func (*MemoryDB) PutRaw

func (b *MemoryDB) PutRaw(bucket []byte, key []byte, value []byte) error

PutRaw will write data to a given bucket using the key

func (*MemoryDB) UnlockFor

func (b *MemoryDB) UnlockFor(time.Duration) (time.Time, error)

type Symmetric

type Symmetric struct {
	DB

	// Retention sets the default key retention policy. A value of zero
	// indicates indefinite key retention.
	Retention time.Duration

	// New indicates that the database is new and the passphrase should be
	// confirmed the first time.
	New bool
	// contains filtered or unexported fields
}

Symmetric implements Encrypted via symmetric encryption using a key derived from a passphrase and a salt.

func NewSymmetric

func NewSymmetric(raw DB) *Symmetric

func OpenSymmetric

func OpenSymmetric(raw DB, passphrase []byte) (*Symmetric, error)

OpenSymmetric creates or opens a symmetrically encrypted database.

func (*Symmetric) Get

func (e *Symmetric) Get(bucket []byte, key []byte) (value []byte, err error)

Get will get an entry in the database given a bucket and key

func (*Symmetric) GetBucket

func (e *Symmetric) GetBucket(bucket []byte) (*Bucket, error)

func (*Symmetric) IsLocked

func (s *Symmetric) IsLocked() bool

func (*Symmetric) Lock

func (s *Symmetric) Lock()

func (*Symmetric) Put

func (e *Symmetric) Put(bucket []byte, key []byte, value []byte) error

Put will write data to a given bucket using the key

func (*Symmetric) Raw

func (s *Symmetric) Raw() DB

func (*Symmetric) UnlockFor

func (s *Symmetric) UnlockFor(passphrase []byte, duration time.Duration) (dl time.Time, err error)

UnlockFor unlocks the wallet, prompting the user to enter the wallet password. UnlockFor locks the database after the specified duration has elapsed.

type Version

type Version uint64

func NewVersion

func NewVersion(commit int, major int, minor int, revision int) Version

func (Version) Bytes

func (v Version) Bytes() []byte

func (Version) Commit

func (v Version) Commit() uint32

func (Version) Compare

func (v Version) Compare(version Version) int

Compare returns < 0 if v < version, returns > 0 if v > version, returns 0 if v == version

func (*Version) FromBytes

func (v *Version) FromBytes(data []byte) Version

func (Version) Major

func (v Version) Major() uint8

func (Version) Minor

func (v Version) Minor() uint8

func (Version) Revision

func (v Version) Revision() uint16

func (Version) String

func (v Version) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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