You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
847 B

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