Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
76907bb4
提交
76907bb4
authored
1月 22, 2018
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
keystore interface docs
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
e0e856aa
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
10 行删除
+16
-10
keystore.go
keystore/keystore.go
+13
-9
memkeystore.go
keystore/memkeystore.go
+3
-1
没有找到文件。
keystore/keystore.go
浏览文件 @
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
浏览文件 @
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
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论