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.

57 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. assert.True(t, testGenerate.PubKey().VerifyBytes(signBytes, testGenerate.Sign(signBytes)))
  12. }
  13. /*
  14. type BadKey struct {
  15. PrivKeyEd25519
  16. }
  17. func TestReadPrivKey(t *testing.T) {
  18. assert, require := assert.New(t), require.New(t)
  19. // garbage in, garbage out
  20. garbage := []byte("hjgewugfbiewgofwgewr")
  21. XXX This test wants to register BadKey globally to go-crypto,
  22. but we don't want to support that.
  23. _, err := PrivKeyFromBytes(garbage)
  24. require.Error(err)
  25. edKey := GenPrivKeyEd25519()
  26. badKey := BadKey{edKey}
  27. cases := []struct {
  28. key PrivKey
  29. valid bool
  30. }{
  31. {edKey, true},
  32. {badKey, false},
  33. }
  34. for i, tc := range cases {
  35. data := tc.key.Bytes()
  36. fmt.Println(">>>", data)
  37. key, err := PrivKeyFromBytes(data)
  38. fmt.Printf("!!! %#v\n", key, err)
  39. if tc.valid {
  40. assert.NoError(err, "%d", i)
  41. assert.Equal(tc.key, key, "%d", i)
  42. } else {
  43. assert.Error(err, "%d: %#v", i, key)
  44. }
  45. }
  46. }
  47. */