Commit 26a481a9 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

fixed key hashing interface + test

parent 11a8826d
......@@ -15,6 +15,8 @@ import (
"math/big"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
u "github.com/jbenet/go-ipfs/util"
)
var ErrBadKeyType = errors.New("invalid or unsupported key type")
......@@ -249,3 +251,12 @@ func KeyEqual(k1, k2 Key) bool {
b2, err2 := k2.Bytes()
return bytes.Equal(b1, b2) && err1 == err2
}
// KeyHash hashes a key.
func KeyHash(k Key) ([]byte, error) {
kb, err := k.Bytes()
if err != nil {
return nil, err
}
return u.Hash(kb)
}
......@@ -92,3 +92,7 @@ func (pk testkey) Bytes() ([]byte, error) {
func (pk testkey) Equals(k Key) bool {
return KeyEqual(pk, k)
}
func (pk testkey) Hash() ([]byte, error) {
return KeyHash(pk)
}
......@@ -9,7 +9,6 @@ import (
"errors"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
u "github.com/jbenet/go-ipfs/util"
)
type RsaPrivateKey struct {
......@@ -48,11 +47,7 @@ func (pk *RsaPublicKey) Equals(k Key) bool {
}
func (pk *RsaPublicKey) Hash() ([]byte, error) {
pkb, err := pk.Bytes()
if err != nil {
return nil, err
}
return u.Hash(pkb)
return KeyHash(pk)
}
func (sk *RsaPrivateKey) GenSecret() []byte {
......@@ -85,11 +80,7 @@ func (sk *RsaPrivateKey) Equals(k Key) bool {
}
func (sk *RsaPrivateKey) Hash() ([]byte, error) {
skb, err := sk.Bytes()
if err != nil {
return nil, err
}
return u.Hash(skb)
return KeyHash(sk)
}
func UnmarshalRsaPrivateKey(b []byte) (*RsaPrivateKey, error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment