Skip to content

Commit c79f0a0

Browse files
dignifiedquireStebalien
authored andcommitted
use equal method from openssl
uses spacemonkeygo/openssl#126
1 parent e64c956 commit c79f0a0

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

core/crypto/openssl_common.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

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

10-
openssl "github.com/spacemonkeygo/openssl"
10+
openssl "github.com/libp2p/go-openssl"
1111
)
1212

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

6464
// Equals checks whether this key is equal to another
6565
func (pk *opensslPublicKey) Equals(k Key) bool {
66-
a, err := pk.Raw()
67-
if err != nil {
68-
return false
69-
}
70-
b, err := k.Raw()
71-
if err != nil {
72-
return false
66+
k0, ok := k.(*RsaPublicKey)
67+
if !ok {
68+
a, err := pk.Raw()
69+
if err != nil {
70+
return false
71+
}
72+
b, err := k.Raw()
73+
if err != nil {
74+
return false
75+
}
76+
77+
return bytes.Equal(a, b)
7378
}
74-
return bytes.Equal(a, b)
79+
80+
return pk.key.Equal(k0.opensslPublicKey.key)
7581
}
7682

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

105111
// Equals checks whether this key is equal to another
106112
func (sk *opensslPrivateKey) Equals(k Key) bool {
107-
a, err := sk.Raw()
108-
if err != nil {
109-
return false
110-
}
111-
b, err := k.Raw()
112-
if err != nil {
113-
return false
113+
k0, ok := k.(*RsaPrivateKey)
114+
if !ok {
115+
a, err := sk.Raw()
116+
if err != nil {
117+
return false
118+
}
119+
b, err := k.Raw()
120+
if err != nil {
121+
return false
122+
}
123+
124+
return bytes.Equal(a, b)
114125
}
115-
return bytes.Equal(a, b)
126+
127+
return sk.key.Equal(k0.opensslPrivateKey.key)
116128
}

core/crypto/rsa_openssl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"errors"
77
"io"
88

9-
openssl "github.com/spacemonkeygo/openssl"
9+
openssl "github.com/libp2p/go-openssl"
1010
)
1111

1212
// RsaPrivateKey is an rsa private key

0 commit comments

Comments
 (0)