Skip to content

Commit

Permalink
use equal method from openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored and Stebalien committed Aug 1, 2019
1 parent e64c956 commit c79f0a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
46 changes: 29 additions & 17 deletions core/crypto/openssl_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

pb "github.com/libp2p/go-libp2p-core/crypto/pb"

openssl "github.com/spacemonkeygo/openssl"
openssl "github.com/libp2p/go-openssl"
)

// define these as separate types so we can add more key types later and reuse
Expand Down Expand Up @@ -63,15 +63,21 @@ func (pk *opensslPublicKey) Raw() ([]byte, error) {

// Equals checks whether this key is equal to another
func (pk *opensslPublicKey) Equals(k Key) bool {
a, err := pk.Raw()
if err != nil {
return false
}
b, err := k.Raw()
if err != nil {
return false
k0, ok := k.(*RsaPublicKey)
if !ok {
a, err := pk.Raw()
if err != nil {
return false
}
b, err := k.Raw()
if err != nil {
return false
}

return bytes.Equal(a, b)
}
return bytes.Equal(a, b)

return pk.key.Equal(k0.opensslPublicKey.key)
}

// Sign returns a signature of the input data
Expand Down Expand Up @@ -104,13 +110,19 @@ func (sk *opensslPrivateKey) Raw() ([]byte, error) {

// Equals checks whether this key is equal to another
func (sk *opensslPrivateKey) Equals(k Key) bool {
a, err := sk.Raw()
if err != nil {
return false
}
b, err := k.Raw()
if err != nil {
return false
k0, ok := k.(*RsaPrivateKey)
if !ok {
a, err := sk.Raw()
if err != nil {
return false
}
b, err := k.Raw()
if err != nil {
return false
}

return bytes.Equal(a, b)
}
return bytes.Equal(a, b)

return sk.key.Equal(k0.opensslPrivateKey.key)
}
2 changes: 1 addition & 1 deletion core/crypto/rsa_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"io"

openssl "github.com/spacemonkeygo/openssl"
openssl "github.com/libp2p/go-openssl"
)

// RsaPrivateKey is an rsa private key
Expand Down

0 comments on commit c79f0a0

Please sign in to comment.