Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c616b7ce
提交
c616b7ce
authored
8月 03, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: key: some changes to match command functionality
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
8d3a350c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
14 行删除
+25
-14
key.go
core/coreapi/interface/key.go
+7
-1
key.go
core/coreapi/key.go
+14
-9
key_test.go
core/coreapi/key_test.go
+4
-4
没有找到文件。
core/coreapi/interface/key.go
浏览文件 @
c616b7ce
...
...
@@ -4,14 +4,20 @@ import (
"context"
options
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
"gx/ipfs/QmdVrMn1LhB4ybb8hMVaMLXnA8XRSewMnK6YqXKXoTcRvN/go-libp2p-peer"
)
// Key specifies the interface to Keys in KeyAPI Keystore
type
Key
interface
{
// Key returns key name
Name
()
string
// Path returns key path
Path
()
Path
// Id returns key PeerID
Id
()
peer
.
ID
}
// KeyAPI specifies the interface to Keystore
...
...
@@ -28,5 +34,5 @@ type KeyAPI interface {
List
(
ctx
context
.
Context
)
([]
Key
,
error
)
// Remove removes keys from keystore. Returns ipns path of the removed key
Remove
(
ctx
context
.
Context
,
name
string
)
(
Path
,
error
)
Remove
(
ctx
context
.
Context
,
name
string
)
(
Key
,
error
)
}
core/coreapi/key.go
浏览文件 @
c616b7ce
...
...
@@ -18,7 +18,7 @@ type KeyAPI CoreAPI
type
key
struct
{
name
string
peerId
string
peerId
peer
.
ID
}
// Name returns the key name
...
...
@@ -28,7 +28,7 @@ func (k *key) Name() string {
// Path returns the path of the key.
func
(
k
*
key
)
Path
()
coreiface
.
Path
{
path
,
err
:=
coreiface
.
ParsePath
(
ipfspath
.
Join
([]
string
{
"/ipns"
,
k
.
peerId
}))
path
,
err
:=
coreiface
.
ParsePath
(
ipfspath
.
Join
([]
string
{
"/ipns"
,
k
.
peerId
.
Pretty
()
}))
if
err
!=
nil
{
panic
(
"error parsing path: "
+
err
.
Error
())
}
...
...
@@ -36,6 +36,11 @@ func (k *key) Path() coreiface.Path {
return
path
}
// Id returns key PeerID
func
(
k
*
key
)
Id
()
peer
.
ID
{
return
k
.
peerId
}
// Generate generates new key, stores it in the keystore under the specified
// name and returns a base58 encoded multihash of its public key.
func
(
api
*
KeyAPI
)
Generate
(
ctx
context
.
Context
,
name
string
,
opts
...
caopts
.
KeyGenerateOption
)
(
coreiface
.
Key
,
error
)
{
...
...
@@ -45,7 +50,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
}
if
name
==
"self"
{
return
nil
,
fmt
.
Errorf
(
"cannot
overwri
te key with name 'self'"
)
return
nil
,
fmt
.
Errorf
(
"cannot
crea
te key with name 'self'"
)
}
_
,
err
=
api
.
node
.
Repo
.
Keystore
()
.
Get
(
name
)
...
...
@@ -91,7 +96,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
return
nil
,
err
}
return
&
key
{
name
,
pid
.
Pretty
()
},
nil
return
&
key
{
name
,
pid
},
nil
}
// List returns a list keys stored in keystore.
...
...
@@ -104,7 +109,7 @@ func (api *KeyAPI) List(ctx context.Context) ([]coreiface.Key, error) {
sort
.
Strings
(
keys
)
out
:=
make
([]
coreiface
.
Key
,
len
(
keys
)
+
1
)
out
[
0
]
=
&
key
{
"self"
,
api
.
node
.
Identity
.
Pretty
()
}
out
[
0
]
=
&
key
{
"self"
,
api
.
node
.
Identity
}
for
n
,
k
:=
range
keys
{
privKey
,
err
:=
api
.
node
.
Repo
.
Keystore
()
.
Get
(
k
)
...
...
@@ -119,7 +124,7 @@ func (api *KeyAPI) List(ctx context.Context) ([]coreiface.Key, error) {
return
nil
,
err
}
out
[
n
+
1
]
=
&
key
{
k
,
pid
.
Pretty
()
}
out
[
n
+
1
]
=
&
key
{
k
,
pid
}
}
return
out
,
nil
}
...
...
@@ -175,11 +180,11 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
return
nil
,
false
,
err
}
return
&
key
{
newName
,
pid
.
Pretty
()
},
overwrite
,
ks
.
Delete
(
oldName
)
return
&
key
{
newName
,
pid
},
overwrite
,
ks
.
Delete
(
oldName
)
}
// Remove removes keys from keystore. Returns ipns path of the removed key.
func
(
api
*
KeyAPI
)
Remove
(
ctx
context
.
Context
,
name
string
)
(
coreiface
.
Path
,
error
)
{
func
(
api
*
KeyAPI
)
Remove
(
ctx
context
.
Context
,
name
string
)
(
coreiface
.
Key
,
error
)
{
ks
:=
api
.
node
.
Repo
.
Keystore
()
if
name
==
"self"
{
...
...
@@ -203,5 +208,5 @@ func (api *KeyAPI) Remove(ctx context.Context, name string) (coreiface.Path, err
return
nil
,
err
}
return
(
&
key
{
""
,
pid
.
Pretty
()})
.
Path
()
,
nil
return
&
key
{
""
,
pid
}
,
nil
}
core/coreapi/key_test.go
浏览文件 @
c616b7ce
...
...
@@ -174,8 +174,8 @@ func TestGenerateExisting(t *testing.T) {
if
err
==
nil
{
t
.
Error
(
"expected error to not be nil"
)
}
else
{
if
err
.
Error
()
!=
"cannot
overwri
te key with name 'self'"
{
t
.
Fatalf
(
"expected error 'cannot
overwri
te key with name 'self'', got '%s'"
,
err
.
Error
())
if
err
.
Error
()
!=
"cannot
crea
te key with name 'self'"
{
t
.
Fatalf
(
"expected error 'cannot
crea
te key with name 'self'', got '%s'"
,
err
.
Error
())
}
}
}
...
...
@@ -396,8 +396,8 @@ func TestRemove(t *testing.T) {
return
}
if
k
.
Path
()
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"k and p should have equal paths, '%s'!='%s'"
,
k
.
Path
()
.
String
(),
p
.
String
())
if
k
.
Path
()
.
String
()
!=
p
.
Path
()
.
String
()
{
t
.
Errorf
(
"k and p should have equal paths, '%s'!='%s'"
,
k
.
Path
()
.
String
(),
p
.
Path
()
.
String
())
}
l
,
err
=
api
.
Key
()
.
List
(
ctx
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论