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.

61 lines
1.2 KiB

  1. package crypto_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. crypto "github.com/tendermint/go-crypto"
  6. )
  7. func TestGeneratePrivKey(t *testing.T) {
  8. testPriv := crypto.GenPrivKeyEd25519()
  9. testGenerate := testPriv.Generate(1)
  10. signBytes := []byte("something to sign")
  11. pub, err := testGenerate.PubKey()
  12. assert.NoError(t, err)
  13. sig, err := testGenerate.Sign(signBytes)
  14. assert.NoError(t, err)
  15. assert.True(t, pub.VerifyBytes(signBytes, sig))
  16. }
  17. /*
  18. type BadKey struct {
  19. PrivKeyEd25519
  20. }
  21. func TestReadPrivKey(t *testing.T) {
  22. assert, require := assert.New(t), require.New(t)
  23. // garbage in, garbage out
  24. garbage := []byte("hjgewugfbiewgofwgewr")
  25. XXX This test wants to register BadKey globally to go-crypto,
  26. but we don't want to support that.
  27. _, err := PrivKeyFromBytes(garbage)
  28. require.Error(err)
  29. edKey := GenPrivKeyEd25519()
  30. badKey := BadKey{edKey}
  31. cases := []struct {
  32. key PrivKey
  33. valid bool
  34. }{
  35. {edKey, true},
  36. {badKey, false},
  37. }
  38. for i, tc := range cases {
  39. data := tc.key.Bytes()
  40. fmt.Println(">>>", data)
  41. key, err := PrivKeyFromBytes(data)
  42. fmt.Printf("!!! %#v\n", key, err)
  43. if tc.valid {
  44. assert.NoError(err, "%d", i)
  45. assert.Equal(tc.key, key, "%d", i)
  46. } else {
  47. assert.Error(err, "%d: %#v", i, key)
  48. }
  49. }
  50. }
  51. */