Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 2df9672

Browse files
dignifiedquireStebalien
authored andcommitted
use equal method from openssl
uses spacemonkeygo/openssl#126
1 parent bab5f6d commit 2df9672

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

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
}

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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ require (
88
github.com/jbenet/goprocess v0.1.3
99
github.com/libp2p/go-flow-metrics v0.0.1
1010
github.com/libp2p/go-msgio v0.0.4
11+
github.com/libp2p/go-openssl v0.0.1
1112
github.com/minio/sha256-simd v0.1.0
1213
github.com/mr-tron/base58 v1.1.2
1314
github.com/multiformats/go-multiaddr v0.0.4
1415
github.com/multiformats/go-multihash v0.0.5
1516
github.com/smola/gocompat v0.2.0
16-
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a
1717
go.opencensus.io v0.21.0
1818
golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443
1919
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atq
6868
github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8=
6969
github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA=
7070
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
71+
github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA=
72+
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
73+
github.com/libp2p/go-openssl v0.0.1 h1:hOIo7l0lXir9UzQE2zPxwd/Gdts1LFik0nqhbDZrG8U=
74+
github.com/libp2p/go-openssl v0.0.1/go.mod h1:v8Zw2ijCSWBQi8Pq5GAixw6DbFfa9u6VIYDXnvOXkc0=
7175
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
7276
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
73-
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
7477
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
75-
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
7678
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
77-
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
7879
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
7980
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
8081
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
@@ -102,12 +103,9 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
102103
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
103104
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
104105
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
105-
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
106106
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
107107
github.com/smola/gocompat v0.2.0 h1:6b1oIMlUXIpz//VKEDzPVBK8KG7beVwmHIUEBIs/Pns=
108108
github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY=
109-
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek=
110-
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0=
111109
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU=
112110
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc=
113111
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
@@ -154,6 +152,8 @@ golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j
154152
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
155153
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
156154
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
155+
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
156+
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
157157
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
158158
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635 h1:2eB4G6bDQDeP69ZXbOKC00S2Kf6TIiRS+DzfKsKeQU0=
159159
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

0 commit comments

Comments
 (0)