mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 20:26:19 +08:00
[SM2] add key equal test
This commit is contained in:
parent
93b04f706d
commit
f97273bb5a
39
smx509/equal_test.go
Normal file
39
smx509/equal_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package smx509
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/emmansun/gmsm/sm2"
|
||||
)
|
||||
|
||||
func TestEqual(t *testing.T) {
|
||||
private, _ := sm2.GenerateKey(rand.Reader)
|
||||
public := &private.PublicKey
|
||||
|
||||
if !public.Equal(public) {
|
||||
t.Errorf("public key is not equal to itself: %q", public)
|
||||
}
|
||||
if !public.Equal(crypto.Signer(private).Public()) {
|
||||
t.Errorf("private.Public() is not Equal to public: %q", public)
|
||||
}
|
||||
if !private.Equal(private) {
|
||||
t.Errorf("private key is not equal to itself: %q", private)
|
||||
}
|
||||
|
||||
enc, err := MarshalPKCS8PrivateKey(private)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
decoded, err := ParsePKCS8PrivateKey(enc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !public.Equal(decoded.(crypto.Signer).Public()) {
|
||||
t.Errorf("public key is not equal to itself after decoding: %v", public)
|
||||
}
|
||||
if !private.Equal(decoded) {
|
||||
t.Errorf("private key is not equal to itself after decoding: %v", private)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user