Documentation ¶
Index ¶
- Variables
- func Decrypt(ciphertext []byte, key []byte) ([]byte, error)
- func Encrypt(plaintext []byte, key []byte) ([]byte, error)
- func GetKey(password, salt []byte) ([]byte, error)
- type BoltDB
- func (b *BoltDB) Close() error
- func (b *BoltDB) Delete(bucket []byte, key []byte) error
- func (b *BoltDB) DeleteBucket(bucket []byte) error
- func (b *BoltDB) Get(bucket []byte, key []byte) (value []byte, err error)
- func (b *BoltDB) GetBucket(bucket []byte) (buck *Bucket, err error)
- func (b *BoltDB) GetRaw(bucket []byte, key []byte) (value []byte, err error)
- func (b *BoltDB) InitDB(filename string, retriever Retriever) (encrypted bool, err error)
- func (b *BoltDB) Lock()
- func (b *BoltDB) Name() string
- func (b *BoltDB) Put(bucket []byte, key []byte, value []byte) error
- func (b *BoltDB) PutRaw(bucket []byte, key []byte, value []byte) error
- func (b *BoltDB) UnlockFor(duration time.Duration) (time.Time, error)
- type Bucket
- type DB
- type Encrypter
- type KeyValue
- type MemoryDB
- func (b *MemoryDB) Close() error
- func (b *MemoryDB) Delete(bucket []byte, key []byte) (err error)
- func (b *MemoryDB) DeleteBucket(bucket []byte) error
- func (b *MemoryDB) Get(bucket []byte, key []byte) (value []byte, err error)
- func (b *MemoryDB) GetBucket(bucket []byte) (buck *Bucket, err error)
- func (b *MemoryDB) GetRaw(bucket []byte, key []byte) (value []byte, err error)
- func (b *MemoryDB) InitDB(string, Retriever) (bool, error)
- func (b *MemoryDB) Lock()
- func (b *MemoryDB) Name() string
- func (b *MemoryDB) Put(bucket []byte, key []byte, value []byte) error
- func (b *MemoryDB) PutRaw(bucket []byte, key []byte, value []byte) error
- func (b *MemoryDB) UnlockFor(time.Duration) (time.Time, error)
- type NoopEncrypter
- type Retriever
- type SymmetricEncrypter
- type Version
Constants ¶
This section is empty.
Variables ¶
var BucketConfig = []byte("Config")
var ErrDatabaseAlreadyEncrypted = errors.New("database already encrypted")
var ErrInvalidPassword = errors.New("invalid password")
var ErrMalformedEncryptedDatabase = errors.New("malformed encrypted database")
var ErrNoBucket = errors2.NotFound.With("bucket not defined")
var ErrNoPassword = errors.New("no password specified for encrypted database")
var ErrNotFound = errors2.NotFound.With("key not found")
var ErrNotOpen = errors.New("database not open")
var WalletVersion = NewVersion(0, 0, 3, 3)
WalletVersion is incremented whenever a bucket format is changed.
Functions ¶
Types ¶
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
func (*BoltDB) DeleteBucket ¶
DeleteBucket will delete all key/value pairs from a bucket
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.
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
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 MemoryDB ¶
type MemoryDB struct {
// contains filtered or unexported fields
}
MemoryDB holds the main map of buckets for the in-memory database
func (*MemoryDB) DeleteBucket ¶
DeleteBucket will delete all key/value pairs from a bucket
func (*MemoryDB) InitDB ¶
InitDB initializes the MemoryDB and must be called prior to use of the object
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()
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()