mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-26 09:54:19 +00:00
Expose new and list via cli
This commit is contained in:
@@ -49,7 +49,7 @@ func (s FileStore) assertStorage() keys.Storage {
|
||||
|
||||
// Put creates two files, one with the public info as json, the other
|
||||
// with the (encoded) private key as gpg ascii-armor style
|
||||
func (s FileStore) Put(name string, key []byte, info keys.KeyInfo) error {
|
||||
func (s FileStore) Put(name string, key []byte, info keys.Info) error {
|
||||
pub, priv := s.nameToPaths(name)
|
||||
|
||||
// write public info
|
||||
@@ -62,10 +62,10 @@ func (s FileStore) Put(name string, key []byte, info keys.KeyInfo) error {
|
||||
return write(priv, name, key)
|
||||
}
|
||||
|
||||
// Get loads the keyinfo and (encoded) private key from the directory
|
||||
// Get loads the info and (encoded) private key from the directory
|
||||
// It uses `name` to generate the filename, and returns an error if the
|
||||
// files don't exist or are in the incorrect format
|
||||
func (s FileStore) Get(name string) ([]byte, keys.KeyInfo, error) {
|
||||
func (s FileStore) Get(name string) ([]byte, keys.Info, error) {
|
||||
pub, priv := s.nameToPaths(name)
|
||||
|
||||
info, err := readInfo(pub)
|
||||
@@ -78,8 +78,8 @@ func (s FileStore) Get(name string) ([]byte, keys.KeyInfo, error) {
|
||||
}
|
||||
|
||||
// List parses the key directory for public info and returns a list of
|
||||
// KeyInfo for all keys located in this directory.
|
||||
func (s FileStore) List() ([]keys.KeyInfo, error) {
|
||||
// Info for all keys located in this directory.
|
||||
func (s FileStore) List() (keys.Infos, error) {
|
||||
dir, err := os.Open(s.keyDir)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "List Keys")
|
||||
@@ -91,7 +91,7 @@ func (s FileStore) List() ([]keys.KeyInfo, error) {
|
||||
|
||||
// filter names for .pub ending and load them one by one
|
||||
// half the files is a good guess for pre-allocating the slice
|
||||
infos := make([]keys.KeyInfo, 0, len(names)/2)
|
||||
infos := make([]keys.Info, 0, len(names)/2)
|
||||
for _, name := range names {
|
||||
if strings.HasSuffix(name, PubExt) {
|
||||
p := path.Join(s.keyDir, name)
|
||||
@@ -124,11 +124,11 @@ func (s FileStore) nameToPaths(name string) (pub, priv string) {
|
||||
return path.Join(s.keyDir, pubName), path.Join(s.keyDir, privName)
|
||||
}
|
||||
|
||||
func writeInfo(path string, info keys.KeyInfo) error {
|
||||
func writeInfo(path string, info keys.Info) error {
|
||||
return write(path, info.Name, info.PubKey.Bytes())
|
||||
}
|
||||
|
||||
func readInfo(path string) (info keys.KeyInfo, err error) {
|
||||
func readInfo(path string) (info keys.Info, err error) {
|
||||
var data []byte
|
||||
data, info.Name, err = read(path)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestBasicCRUD(t *testing.T) {
|
||||
name := "bar"
|
||||
key := []byte("secret-key-here")
|
||||
pubkey := crypto.GenPrivKeyEd25519().PubKey()
|
||||
info := keys.KeyInfo{
|
||||
info := keys.Info{
|
||||
Name: name,
|
||||
PubKey: crypto.PubKeyS{pubkey},
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type data struct {
|
||||
info keys.KeyInfo
|
||||
info keys.Info
|
||||
key []byte
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func (s MemStore) assertStorage() keys.Storage {
|
||||
|
||||
// Put adds the given key, returns an error if it another key
|
||||
// is already stored under this name
|
||||
func (s MemStore) Put(name string, key []byte, info keys.KeyInfo) error {
|
||||
func (s MemStore) Put(name string, key []byte, info keys.Info) error {
|
||||
if _, ok := s[name]; ok {
|
||||
return errors.Errorf("Key named '%s' already exists", name)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func (s MemStore) Put(name string, key []byte, info keys.KeyInfo) error {
|
||||
}
|
||||
|
||||
// Get returns the key stored under the name, or returns an error if not present
|
||||
func (s MemStore) Get(name string) ([]byte, keys.KeyInfo, error) {
|
||||
func (s MemStore) Get(name string) ([]byte, keys.Info, error) {
|
||||
var err error
|
||||
d, ok := s[name]
|
||||
if !ok {
|
||||
@@ -48,8 +48,8 @@ func (s MemStore) Get(name string) ([]byte, keys.KeyInfo, error) {
|
||||
}
|
||||
|
||||
// List returns the public info of all keys in the MemStore in unsorted order
|
||||
func (s MemStore) List() ([]keys.KeyInfo, error) {
|
||||
res := make([]keys.KeyInfo, len(s))
|
||||
func (s MemStore) List() (keys.Infos, error) {
|
||||
res := make([]keys.Info, len(s))
|
||||
i := 0
|
||||
for _, d := range s {
|
||||
res[i] = d.info
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestBasicCRUD(t *testing.T) {
|
||||
name := "foo"
|
||||
key := []byte("secret-key-here")
|
||||
pubkey := crypto.GenPrivKeyEd25519().PubKey()
|
||||
info := keys.KeyInfo{
|
||||
info := keys.Info{
|
||||
Name: name,
|
||||
PubKey: crypto.PubKeyS{pubkey},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user