35 lines
657 B
Go
35 lines
657 B
Go
package langext
|
|
|
|
import (
|
|
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
|
|
"testing"
|
|
)
|
|
|
|
func TestRandBytesLength(t *testing.T) {
|
|
for _, sz := range []int{0, 1, 16, 32, 1024} {
|
|
b := RandBytes(sz)
|
|
tst.AssertEqual(t, len(b), sz)
|
|
}
|
|
}
|
|
|
|
func TestRandBytesDistinct(t *testing.T) {
|
|
a := RandBytes(32)
|
|
b := RandBytes(32)
|
|
|
|
// Two cryptographic random sequences should not be equal in 32 bytes.
|
|
if len(a) != 32 || len(b) != 32 {
|
|
t.Fatalf("unexpected length")
|
|
}
|
|
|
|
equal := true
|
|
for i := range a {
|
|
if a[i] != b[i] {
|
|
equal = false
|
|
break
|
|
}
|
|
}
|
|
if equal {
|
|
t.Errorf("two consecutive 32-byte RandBytes calls returned identical results")
|
|
}
|
|
}
|