github.com/mad-day/Yawning-crypto@v0.0.0-20190711051033-5a5f8cca32ec/morus/burn_test.go (about) 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 8 package morus 9 10 import ( 11 "crypto/rand" 12 "encoding/binary" 13 "testing" 14 15 "github.com/stretchr/testify/require" 16 ) 17 18 // While it seems somewhat silly to test memset, the unsafe implementation 19 // uses trickery to reach into the runtime library, so it's worth exercising. 20 21 func TestBurnBytes(t *testing.T) { 22 require := require.New(t) 23 24 var buf [1024]byte 25 require.Zero(buf, "buf: Before random read") 26 _, err := rand.Read(buf[:]) 27 require.NoError(err, "rand.Read()") 28 require.NotZero(buf, "buf: After random read") 29 30 burnBytes(buf[:]) 31 require.Zero(buf, "buf: After burnBytes()") 32 } 33 34 func TestBurnUint64s(t *testing.T) { 35 require := require.New(t) 36 37 var buf [1024]uint64 38 require.Zero(buf, "buf: Before random read") 39 40 err := binary.Read(rand.Reader, binary.LittleEndian, &buf) 41 require.NoError(err, "binary.Read(rand.Reader)") 42 require.NotZero(buf, "buf: After random read") 43 44 burnUint64s(buf[:]) 45 require.Zero(buf, "buf: After burnUint64s()") 46 }