db

package
v1.0.0-rc3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BucketConfig = []byte("Config")
View Source
var ErrDatabaseAlreadyEncrypted = errors.New("database already encrypted")
View Source
var ErrDatabaseNotEncrypted = errors.New("database not encrypted")
View Source
var ErrInvalidPassword = errors.New("invalid password")
View Source
var ErrMalformedEncryptedDatabase = errors.New("malformed encrypted database")
View Source
var ErrNoBucket = errors.New("bucket not defined")
View Source
var ErrNoPassword = errors.New("no password specified for encrypted database")
View Source
var ErrNotFound = errors.New("key not found")
View Source
var ErrNotOpen = errors.New("database not open")
View Source
var WalletVersion = NewVersion(0, 0, 1, 1)

WalletVersion is incremented whenever a bucket format is changed.

Functions

func Decrypt added in v0.6.0

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

func Encrypt added in v0.6.0

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

func GetKey added in v0.6.0

func GetKey(password string, salt []byte) ([]byte, error)

Types

type BoltDB

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

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) 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) GetRaw added in v0.6.0

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

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

func (*BoltDB) InitDB

func (b *BoltDB) InitDB(filename string, password string) (err error)

InitDB will open the database

func (*BoltDB) Name added in v0.6.0

func (b *BoltDB) Name() string

func (*BoltDB) Put

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

Put will write data to a given bucket using the key

func (*BoltDB) PutRaw added in v0.6.0

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

type Bucket

type Bucket struct {
	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) 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
	InitDB(filepath string, password string) error              // Sets up the database, returns error if it fails
	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
	GetRaw(bucket []byte, key []byte) (value []byte, err error) // GetRaw value as-is from database using key, returns ErrNotFound if the key is not found
	PutRaw(bucket []byte, key []byte, value []byte) error       // PutRaw the value in the database as-is, 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 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 added in v0.6.0

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) InitDB

func (b *MemoryDB) InitDB(string, string) (err error)

InitDB initializes the MemoryDB and must be called prior to use of the object

func (*MemoryDB) Name added in v0.6.0

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 added in v0.6.0

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

PutRaw will write data to a given bucket using the key

type Version added in v0.6.0

type Version uint64

func NewVersion added in v0.6.0

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

func (Version) Bytes added in v0.6.0

func (v Version) Bytes() []byte

func (Version) Commit added in v0.6.0

func (v Version) Commit() uint32

func (Version) Compare added in v0.6.0

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 added in v0.6.0

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

func (Version) Major added in v0.6.0

func (v Version) Major() uint8

func (Version) Minor added in v0.6.0

func (v Version) Minor() uint8

func (Version) Revision added in v0.6.0

func (v Version) Revision() uint16

func (Version) String added in v0.6.0

func (v Version) String() string

Jump to

Keyboard shortcuts

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