Skip to content

Commit

Permalink
use b36 keys by default for keys and IPNS
Browse files Browse the repository at this point in the history
  • Loading branch information
petar committed Aug 18, 2020
1 parent 8ae5aa5 commit 3cbe111
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var keyGenCmd = &cmds.Command{
Options: []cmds.Option{
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault),
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
},
Arguments: []cmds.Argument{
cmds.StringArg("name", true, false, "name of key to create"),
Expand Down Expand Up @@ -298,7 +298,7 @@ var keyListCmd = &cmds.Command{
},
Options: []cmds.Option{
cmds.BoolOption("l", "Show extra information about keys."),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
Expand Down
34 changes: 17 additions & 17 deletions core/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ Resolve the value of an IPFS DAG path:
name := req.Arguments[0]
recursive, _ := req.Options[resolveRecursiveOptionName].(bool)

var enc cidenc.Encoder
switch {
case !cmdenv.CidBaseDefined(req):
// Not specified, check the path.
enc, err = cmdenv.CidEncoderFromPath(name)
if err == nil {
break
}
// Nope, fallback on the default.
fallthrough
default:
enc, err = cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
}

// the case when ipns is resolved step by step
if strings.HasPrefix(name, "/ipns/") && !recursive {
rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
Expand Down Expand Up @@ -128,6 +111,23 @@ Resolve the value of an IPFS DAG path:
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: ipfspath.Path(p.String())})
}

var enc cidenc.Encoder
switch {
case !cmdenv.CidBaseDefined(req) && !strings.HasPrefix(name, "/ipns/"):
// Not specified, check the path.
enc, err = cmdenv.CidEncoderFromPath(name)
if err == nil {
break
}
// Nope, fallback on the default.
fallthrough
default:
enc, err = cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
}

// else, ipfs path or ipns with recursive flag
rp, err := api.ResolvePath(req.Context, path.New(name))
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions test/sharness/t0160-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ test_expect_success "resolve: prepare dag" '
'

test_expect_success "resolve: prepare keys" '
self_hash=$(ipfs id -f="<id>") &&
alt_hash=$(ipfs key gen -f=b58mh -t rsa alt)
self_hash=$(ipfs key list -f=b36cid -l | grep self | cut -d " " -f1) &&
alt_hash=$(ipfs key gen -f=b36cid -t rsa alt)
echo self_hash $self_hash
echo $(ipfs id -f="<id>")
'

test_resolve_setup_name() {
Expand Down Expand Up @@ -60,6 +62,7 @@ test_resolve() {
}

test_resolve_cmd() {
echo '-- starting test_resolve_cmd'
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
Expand Down Expand Up @@ -96,6 +99,7 @@ test_resolve_cmd() {
}

test_resolve_cmd_b32() {
echo '-- starting test_resolve_cmd_b32'
# no flags needed, base should be preserved

test_resolve "/ipfs/$a_hash_b32" "/ipfs/$a_hash_b32"
Expand Down
12 changes: 6 additions & 6 deletions test/sharness/t0165-keystore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ ipfs key rm key_ed25519


test_expect_success "create a new rsa key" '
rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048)
rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048 -f=b58mh)
echo $rsahash > rsa_key_id
'

test_expect_success "create a new ed25519 key" '
edhash=$(ipfs key gen generated_ed25519_key --type=ed25519)
edhash=$(ipfs key gen generated_ed25519_key --type=ed25519 -f=b58mh)
echo $edhash > ed25519_key_id
'

Expand Down Expand Up @@ -119,13 +119,13 @@ ipfs key rm key_ed25519
'

test_expect_success "key hashes show up in long list output" '
ipfs key list -l | grep $edhash > /dev/null &&
ipfs key list -l | grep $rsahash > /dev/null
ipfs key list -l -f=b58mh | grep $edhash > /dev/null &&
ipfs key list -l -f=b58mh | grep $rsahash > /dev/null
'

test_expect_success "key list -l contains self key with peerID" '
PeerID="$(ipfs config Identity.PeerID)"
ipfs key list -l | grep "$PeerID\s\+self"
ipfs key list -l -f=b58mh | grep "$PeerID\s\+self"
'

test_expect_success "key rm remove a key" '
Expand All @@ -152,7 +152,7 @@ ipfs key rm key_ed25519
'

test_expect_success "key rename rename key output succeeds" '
key_content=$(ipfs key gen key1 --type=rsa --size=2048) &&
key_content=$(ipfs key gen key1 --type=rsa --size=2048 -f=b58mh) &&
ipfs key rename key1 key2 >rs &&
echo "Key $key_content renamed to key2" >expect &&
test_cmp rs expect
Expand Down

0 comments on commit 3cbe111

Please sign in to comment.