Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
26a481a9
Commit
26a481a9
authored
Oct 01, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed key hashing interface + test
parent
11a8826d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
11 deletions
+17
-11
crypto/key.go
crypto/key.go
+11
-0
crypto/key_test.go
crypto/key_test.go
+4
-0
crypto/rsa.go
crypto/rsa.go
+2
-11
No files found.
crypto/key.go
View file @
26a481a9
...
...
@@ -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
)
}
crypto/key_test.go
View file @
26a481a9
...
...
@@ -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
)
}
crypto/rsa.go
View file @
26a481a9
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment