1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 func TestEqual(t
*testing
.T
) {
16 private
, _
:= rsa
.GenerateKey(rand
.Reader
, 512)
17 public
:= &private
.PublicKey
19 if !public
.Equal(public
) {
20 t
.Errorf("public key is not equal to itself: %v", public
)
22 if !public
.Equal(crypto
.Signer(private
).Public().(*rsa
.PublicKey
)) {
23 t
.Errorf("private.Public() is not Equal to public: %q", public
)
25 if !private
.Equal(private
) {
26 t
.Errorf("private key is not equal to itself: %v", private
)
29 enc
, err
:= x509
.MarshalPKCS8PrivateKey(private
)
33 decoded
, err
:= x509
.ParsePKCS8PrivateKey(enc
)
37 if !public
.Equal(decoded
.(crypto
.Signer
).Public()) {
38 t
.Errorf("public key is not equal to itself after decoding: %v", public
)
40 if !private
.Equal(decoded
) {
41 t
.Errorf("private key is not equal to itself after decoding: %v", private
)
44 other
, _
:= rsa
.GenerateKey(rand
.Reader
, 512)
45 if public
.Equal(other
.Public()) {
46 t
.Errorf("different public keys are Equal")
48 if private
.Equal(other
) {
49 t
.Errorf("different private keys are Equal")