github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/jls/fake_random_test.go (about) 1 package jls 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestFakeRandom(t *testing.T) { 10 fakeRandom1 := NewFakeRandom([]byte("abc"), []byte("abc")) 11 fakeRandom2 := NewFakeRandom([]byte("abc"), []byte("abc")) 12 fakeRandom3 := NewFakeRandom([]byte("abc"), []byte("ab")) 13 assert.Equal(t, fakeRandom1.IV, fakeRandom2.IV) 14 assert.Equal(t, fakeRandom1.PWD, fakeRandom2.PWD) 15 assert.Equal(t, fakeRandom1.PWD, fakeRandom3.PWD) 16 assert.NotEqual(t, fakeRandom1.IV, fakeRandom3.IV) 17 18 err := fakeRandom1.Build() 19 assert.Equal(t, len(fakeRandom1.Random), 32) 20 assert.Nil(t, err) 21 22 isValid, err := fakeRandom2.Check(fakeRandom1.Random) 23 assert.Nil(t, err) 24 assert.Equal(t, isValid, true) 25 26 assert.Equal(t, fakeRandom1.N, fakeRandom2.N) 27 assert.Equal(t, fakeRandom1.Random, fakeRandom2.Random) 28 29 isValid, err = fakeRandom3.Check(fakeRandom1.Random) 30 assert.NotNil(t, err) 31 assert.Equal(t, isValid, false) 32 33 random1 := fakeRandom1.Random 34 err = fakeRandom1.Build() 35 assert.Nil(t, err) 36 assert.NotEqual(t, random1, fakeRandom1.Random) 37 }