1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 16:07:42 +08:00

Merge pull request #2340 from ipfs/fix/key-escape

fix dht command key escaping
This commit is contained in:
Jeromy Johnson
2016-04-08 12:20:06 -07:00
2 changed files with 32 additions and 1 deletions

View File

@ -573,7 +573,7 @@ func escapeDhtKey(s string) (key.Key, error) {
return key.B58KeyDecode(s), nil
case 3:
k := key.B58KeyDecode(parts[2])
return key.Key(path.Join(append(parts[:2], k.String()))), nil
return key.Key(path.Join(append(parts[:2], string(k)))), nil
default:
return "", errors.New("invalid key")
}

31
core/commands/dht_test.go Normal file
View File

@ -0,0 +1,31 @@
package commands
import (
"testing"
"github.com/ipfs/go-ipfs/namesys"
tu "github.com/ipfs/go-ipfs/thirdparty/testutil"
)
func TestKeyTranslation(t *testing.T) {
pid := tu.RandPeerIDFatal(t)
a, b := namesys.IpnsKeysForID(pid)
pkk, err := escapeDhtKey("/pk/" + pid.Pretty())
if err != nil {
t.Fatal(err)
}
ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty())
if err != nil {
t.Fatal(err)
}
if pkk != a {
t.Fatal("keys didnt match!")
}
if ipnsk != b {
t.Fatal("keys didnt match!")
}
}