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.

51 lines
936 B

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