burn_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // burn_test.go - burn tests
  2. //
  3. // To the extent possible under law, Yawning Angel has waived all copyright
  4. // and related or neighboring rights to the software, using the Creative
  5. // Commons "CC0" public domain dedication. See LICENSE or
  6. // <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
  7. package norx
  8. import (
  9. "crypto/rand"
  10. "encoding/binary"
  11. "testing"
  12. "github.com/stretchr/testify/require"
  13. )
  14. // While it seems somewhat silly to test memset, the unsafe implementation
  15. // uses trickery to reach into the runtime library, so it's worth exercising.
  16. func TestBurnBytes(t *testing.T) {
  17. require := require.New(t)
  18. var buf [1024]byte
  19. require.Zero(buf, "buf: Before random read")
  20. _, err := rand.Read(buf[:])
  21. require.NoError(err, "rand.Read()")
  22. require.NotZero(buf, "buf: After random read")
  23. burnBytes(buf[:])
  24. require.Zero(buf, "buf: After burnBytes()")
  25. }
  26. func TestBurnUint64s(t *testing.T) {
  27. require := require.New(t)
  28. var buf [1024]uint64
  29. require.Zero(buf, "buf: Before random read")
  30. err := binary.Read(rand.Reader, binary.LittleEndian, &buf)
  31. require.NoError(err, "binary.Read(rand.Reader)")
  32. require.NotZero(buf, "buf: After random read")
  33. burnUint64s(buf[:])
  34. require.Zero(buf, "buf: After burnUint64s()")
  35. }