db

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 15 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 ErrInvalidPassword = errors.New("invalid password")
View Source
var ErrMalformedEncryptedDatabase = errors.New("malformed encrypted database")
View Source
var ErrNoBucket = errors2.NotFound.With("bucket not defined")
View Source
var ErrNoPassword = errors.New("no password specified for encrypted database")
View Source
var ErrNotFound = errors2.NotFound.With("key not found")
View Source
var ErrNotOpen = errors.New("database not open")
View Source
var WalletVersion = NewVersion(0, 0, 3, 3)

WalletVersion is incremented whenever a bucket format is changed.

Functions

func Decrypt

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

func Encrypt

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

func GetKey

func GetKey(password, 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

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, retriever Retriever) (encrypted bool, err error)

InitDB will open the database

func (*BoltDB) Lock added in v0.4.0

func (b *BoltDB) Lock()

Lock locks the database such that subsequent calls to Get/Put will require the user to enter the wallet password.

func (*BoltDB) Name

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

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

func (*BoltDB) UnlockFor added in v0.4.0

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

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

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, retriever Retriever) (bool, 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
	Lock()                                                      // Lock the database
	UnlockFor(time.Duration) (time.Time, error)                 // Unlock the database for a specified duration
}

DB defines the interface functions to access the database

type Encrypter added in v0.4.0

type Encrypter interface {
	// Lock locks the encrypter.
	Lock()

	// Unlock 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.
	Unlock(deadline time.Time) (time.Time, error)

	// Decrypt decrypts a value.
	Decrypt(value []byte) ([]byte, error)

	// Encrypt encrypts a value.
	Encrypt(value []byte) ([]byte, error)
}

Encrypter handles encryption and decryption of values and manages the encryption key.

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

func (b *MemoryDB) InitDB(string, Retriever) (bool, error)

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

func (*MemoryDB) Lock added in v0.4.0

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

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

type NoopEncrypter added in v0.4.0

type NoopEncrypter struct{}

NoopEncrypter is an implementation of Encrypter for unencrypted wallets.

func (NoopEncrypter) Decrypt added in v0.4.0

func (NoopEncrypter) Decrypt(value []byte) ([]byte, error)

func (NoopEncrypter) Encrypt added in v0.4.0

func (NoopEncrypter) Encrypt(value []byte) ([]byte, error)

func (NoopEncrypter) Lock added in v0.4.0

func (NoopEncrypter) Lock()

func (NoopEncrypter) Unlock added in v0.4.0

func (NoopEncrypter) Unlock(deadline time.Time) (time.Time, error)

type Retriever added in v0.4.0

type Retriever interface {
	Retrieve(db DB, confirm bool) ([]byte, error)
}

Retriever retrieves a passphrase

type SymmetricEncrypter added in v0.4.0

type SymmetricEncrypter struct {
	// Database stores the salt.
	Database DB

	// Retriever retrieves the passphrase.
	Retriever Retriever

	// 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
}

SymmetricEncrypter implements Encrypter via symmetric encryption using a key derived from a passphrase and a salt.

func (*SymmetricEncrypter) Decrypt added in v0.4.0

func (s *SymmetricEncrypter) Decrypt(value []byte) ([]byte, error)

func (*SymmetricEncrypter) Encrypt added in v0.4.0

func (s *SymmetricEncrypter) Encrypt(value []byte) ([]byte, error)

func (*SymmetricEncrypter) Lock added in v0.4.0

func (s *SymmetricEncrypter) Lock()

func (*SymmetricEncrypter) Unlock added in v0.4.0

func (s *SymmetricEncrypter) Unlock(deadline time.Time) (time.Time, error)

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

Jump to

Keyboard shortcuts

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