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.

47 lines
864 B

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package crypto
  2. import (
  3. "crypto/rand"
  4. "testing"
  5. )
  6. func TestSign(t *testing.T) {
  7. privKey := make([]byte, 32)
  8. _, err := rand.Read(privKey)
  9. if err != nil {
  10. t.Fatal(err)
  11. }
  12. pubKey := MakePubKey(privKey)
  13. signature := SignMessage([]byte("hello"), privKey, pubKey)
  14. v1 := &Verify{
  15. Message: []byte("hello"),
  16. PubKey: pubKey,
  17. Signature: signature,
  18. }
  19. ok := VerifyBatch([]*Verify{v1, v1, v1, v1})
  20. if ok != true {
  21. t.Fatal("Expected ok == true")
  22. }
  23. if v1.Valid != true {
  24. t.Fatal("Expected v1.Valid to be true")
  25. }
  26. v2 := &Verify{
  27. Message: []byte{0x73},
  28. PubKey: pubKey,
  29. Signature: signature,
  30. }
  31. ok = VerifyBatch([]*Verify{v1, v1, v1, v2})
  32. if ok != false {
  33. t.Fatal("Expected ok == false")
  34. }
  35. if v1.Valid != true {
  36. t.Fatal("Expected v1.Valid to be true")
  37. }
  38. if v2.Valid != false {
  39. t.Fatal("Expected v2.Valid to be true")
  40. }
  41. }