Skip to content

Commit

Permalink
Document exported symbols
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Michael Muré <batolettre@gmail.com>
  • Loading branch information
MichaelMure committed May 14, 2017
1 parent cb8d5eb commit 2593495
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type KeyOutputList struct {
Keys []KeyOutput
}

// KeyRenameOutput define the output type of keyRenameCmd
type KeyRenameOutput struct {
Was string
Now string
Expand Down
10 changes: 10 additions & 0 deletions keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import (
)

type Keystore interface {
// Has return whether or not a key exist in the Keystore
Has(string) (bool, error)
// Put store a key in the Keystore
Put(string, ci.PrivKey) error
// Get retrieve a key from the Keystore
Get(string) (ci.PrivKey, error)
// Delete remove a key from the Keystore
Delete(string) error
// List return a list of key identifier
List() ([]string, error)
}

Expand Down Expand Up @@ -55,6 +60,7 @@ func NewFSKeystore(dir string) (*FSKeystore, error) {
return &FSKeystore{dir}, nil
}

// Has return whether or not a key exist in the Keystore
func (ks *FSKeystore) Has(name string) (bool, error) {
kp := filepath.Join(ks.dir, name)

Expand All @@ -71,6 +77,7 @@ func (ks *FSKeystore) Has(name string) (bool, error) {
return true, nil
}

// Put store a key in the Keystore
func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
if err := validateName(name); err != nil {
return err
Expand Down Expand Up @@ -104,6 +111,7 @@ func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
return nil
}

// Get retrieve a key from the Keystore
func (ks *FSKeystore) Get(name string) (ci.PrivKey, error) {
if err := validateName(name); err != nil {
return nil, err
Expand All @@ -122,6 +130,7 @@ func (ks *FSKeystore) Get(name string) (ci.PrivKey, error) {
return ci.UnmarshalPrivateKey(data)
}

// Delete remove a key from the Keystore
func (ks *FSKeystore) Delete(name string) error {
if err := validateName(name); err != nil {
return err
Expand All @@ -132,6 +141,7 @@ func (ks *FSKeystore) Delete(name string) error {
return os.Remove(kp)
}

// List return a list of key identifier
func (ks *FSKeystore) List() ([]string, error) {
dir, err := os.Open(ks.dir)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions keystore/memkeystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ func NewMemKeystore() *MemKeystore {
return &MemKeystore{make(map[string]ci.PrivKey)}
}

// Has return whether or not a key exist in the Keystore
func (mk *MemKeystore) Has(name string) (bool, error) {
_, ok := mk.keys[name]
return ok, nil
}

// Put store a key in the Keystore
func (mk *MemKeystore) Put(name string, k ci.PrivKey) error {
if err := validateName(name); err != nil {
return err
Expand All @@ -29,6 +31,7 @@ func (mk *MemKeystore) Put(name string, k ci.PrivKey) error {
return nil
}

// Get retrieve a key from the Keystore
func (mk *MemKeystore) Get(name string) (ci.PrivKey, error) {
if err := validateName(name); err != nil {
return nil, err
Expand All @@ -42,6 +45,7 @@ func (mk *MemKeystore) Get(name string) (ci.PrivKey, error) {
return k, nil
}

// Delete remove a key from the Keystore
func (mk *MemKeystore) Delete(name string) error {
if err := validateName(name); err != nil {
return err
Expand All @@ -51,6 +55,7 @@ func (mk *MemKeystore) Delete(name string) error {
return nil
}

// List return a list of key identifier
func (mk *MemKeystore) List() ([]string, error) {
out := make([]string, 0, len(mk.keys))
for k, _ := range mk.keys {
Expand Down

0 comments on commit 2593495

Please sign in to comment.