Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
76907bb4
Commit
76907bb4
authored
Jan 22, 2018
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
keystore interface docs
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
e0e856aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
keystore/keystore.go
keystore/keystore.go
+13
-9
keystore/memkeystore.go
keystore/memkeystore.go
+3
-1
No files found.
keystore/keystore.go
View file @
76907bb4
...
...
@@ -10,22 +10,25 @@ import (
ci
"gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
)
// Keystore provides a key management interface
type
Keystore
interface
{
// Has return whether or not a key exist in the Keystore
// Has return
s
whether or not a key exist in the Keystore
Has
(
string
)
(
bool
,
error
)
// Put store a key in the Keystore
// Put store
s
a key in the Keystore
, if a key with the same name already exists, returns ErrKeyExists
Put
(
string
,
ci
.
PrivKey
)
error
// Get retrieve a key from the Keystore
// Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey
// otherwise.
Get
(
string
)
(
ci
.
PrivKey
,
error
)
// Delete remove a key from the Keystore
// Delete remove
s
a key from the Keystore
Delete
(
string
)
error
// List return a list of key identifier
// List return
s
a list of key identifier
List
()
([]
string
,
error
)
}
var
ErrNoSuchKey
=
fmt
.
Errorf
(
"no key by the given name was found"
)
var
ErrKeyExists
=
fmt
.
Errorf
(
"key by that name already exists, refusing to overwrite"
)
// FSKeystore is a keystore backed by files in a given directory stored on disk.
type
FSKeystore
struct
{
dir
string
}
...
...
@@ -60,7 +63,7 @@ func NewFSKeystore(dir string) (*FSKeystore, error) {
return
&
FSKeystore
{
dir
},
nil
}
// Has return whether or not a key exist in the Keystore
// Has return
s
whether or not a key exist in the Keystore
func
(
ks
*
FSKeystore
)
Has
(
name
string
)
(
bool
,
error
)
{
kp
:=
filepath
.
Join
(
ks
.
dir
,
name
)
...
...
@@ -77,7 +80,7 @@ func (ks *FSKeystore) Has(name string) (bool, error) {
return
true
,
nil
}
// Put store a key in the Keystore
// Put store
s
a key in the Keystore
, if a key with the same name already exists, returns ErrKeyExists
func
(
ks
*
FSKeystore
)
Put
(
name
string
,
k
ci
.
PrivKey
)
error
{
if
err
:=
validateName
(
name
);
err
!=
nil
{
return
err
...
...
@@ -108,7 +111,8 @@ func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
return
err
}
// Get retrieve a key from the Keystore
// Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey
// otherwise.
func
(
ks
*
FSKeystore
)
Get
(
name
string
)
(
ci
.
PrivKey
,
error
)
{
if
err
:=
validateName
(
name
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -127,7 +131,7 @@ func (ks *FSKeystore) Get(name string) (ci.PrivKey, error) {
return
ci
.
UnmarshalPrivateKey
(
data
)
}
// Delete remove a key from the Keystore
// Delete remove
s
a key from the Keystore
func
(
ks
*
FSKeystore
)
Delete
(
name
string
)
error
{
if
err
:=
validateName
(
name
);
err
!=
nil
{
return
err
...
...
keystore/memkeystore.go
View file @
76907bb4
...
...
@@ -2,6 +2,8 @@ package keystore
import
ci
"gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
// MemKeystore is an in memory keystore implementation that is not persisted to
// any backing storage.
type
MemKeystore
struct
{
keys
map
[
string
]
ci
.
PrivKey
}
...
...
@@ -58,7 +60,7 @@ func (mk *MemKeystore) Delete(name string) error {
// 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
{
for
k
:=
range
mk
.
keys
{
out
=
append
(
out
,
k
)
}
return
out
,
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment