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.

26 lines
663 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 of message: %s\n", msgSign)
  16. v, err := s.Verify(message, msgSign, pub)
  17. if err != nil {
  18. t.Errorf("Verification error: %s\n", err)
  19. }
  20. if !v {
  21. t.Error("Verification failed!")
  22. }
  23. t.Logf("Testing verification... %t\n", v)
  24. }