arnaucube
arnaucube/go-dvotePublic Self-hosted repository
go-dvote/crypto/signature_ecdsa/signature_test.go
crypto/signature_ecdsa/signature_test.goRaw
 1package signature
 2
 3import "testing"
 4
 5func TestSignature(t *testing.T) {
 6	t.Log("Testing signature creation and verification")
 7	var s SignKeys
 8	s.Generate()
 9	pub, priv := s.HexString()
10	t.Logf("Generated pub:%s priv:%s\n", pub, priv)
11	message := "Hello, this is gonna be signed!"
12	t.Logf("Message to sign: %s\n", message)
13	msgSign, err := s.Sign(message)
14	if err != nil {
15		t.Errorf("Error while signing %s\n", err)
16	}
17	t.Logf("Signature is %s\n", msgSign)
18
19	var s2 SignKeys
20	err = s2.AddHexKey(priv)
21	if err != nil {
22		t.Errorf("Error importing hex privKey: %s\n", err)
23	}
24	pub, priv = s2.HexString()
25	t.Logf("Imported pub:%s priv:%s\n", pub, priv)
26	v, err := s.Verify(message, msgSign, pub)
27	if err != nil {
28		t.Errorf("Verification error: %s\n", err)
29	}
30	if !v {
31		t.Error("Verification failed!")
32	}
33	t.Logf("Testing verification... %t\n", v)
34}