Skip to content

Commit

Permalink
Merge review comments/changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia committed Oct 22, 2018
1 parent 6c623b2 commit add15b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,26 @@ func ReadPassphraseFromStdin(name string) (string, error) {

// TODO make keybase take a database not load from the directory

// initialize a keybase based on the configuration
// GetKeyBase initializes a keybase based on the configuration.
func GetKeyBase() (keys.Keybase, error) {
rootDir := viper.GetString(cli.HomeFlag)
return getKeyBaseFromDirWithOpts(rootDir, &opt.Options{ReadOnly: true})
return GetKeyBaseFromDir(rootDir)
}

// initialize a keybase based on the configuration with write permission
// GetKeyBaseWithWritePerm initialize a keybase based on the configuration with write permissions.
func GetKeyBaseWithWritePerm() (keys.Keybase, error) {
rootDir := viper.GetString(cli.HomeFlag)
return GetKeyBaseFromDirWithWritePerm(rootDir)
}

// initialize a keybase at particular dir with write permission
// GetKeyBaseFromDirWithWritePerm initializes a keybase at a particular dir with write permissions.
func GetKeyBaseFromDirWithWritePerm(rootDir string) (keys.Keybase, error) {
return getKeyBaseFromDirWithOpts(rootDir, &opt.Options{ReadOnly: false})
return getKeyBaseFromDirWithOpts(rootDir, nil)
}

// GetKeyBaseFromDir initializes a read-only keybase at a particular dir.
func GetKeyBaseFromDir(rootDir string) (keys.Keybase, error) {
return getKeyBaseFromDirWithOpts(rootDir, &opt.Options{ReadOnly: true})
}

func getKeyBaseFromDirWithOpts(rootDir string, o *opt.Options) (keys.Keybase, error) {
Expand Down
5 changes: 5 additions & 0 deletions crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ func (kb dbKeybase) Update(name, oldpass string, getNewpass func() (string, erro
}
}

// CloseDB releases the lock and closes the storage backend.
func (kb dbKeybase) CloseDB() {
kb.db.Close()
}

func (kb dbKeybase) writeLocalKey(priv tmcrypto.PrivKey, name, passphrase string) Info {
// encrypt private key using passphrase
privArmor := mintkey.EncryptArmorPrivKey(priv, passphrase)
Expand Down
3 changes: 3 additions & 0 deletions crypto/keys/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type Keybase interface {

// *only* works on locally-stored keys. Temporary method until we redo the exporting API
ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error)

// Close closes the database.
CloseDB()
}

// KeyType reflects a human-readable type for key listing.
Expand Down

0 comments on commit add15b5

Please sign in to comment.