-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcrypto_test.go
49 lines (44 loc) · 1 KB
/
crypto_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package randutil
import (
"regexp"
"testing"
)
func TestCryptoRandomGenerator(t *testing.T) {
isLetter := regexp.MustCompile(`^[a-zA-Z]+$`).MatchString
for i := 0; i < 10000; i++ {
s, err := GenerateCryptoRandomString(10, runesAlpha)
if err != nil {
t.Error(err)
}
if len(s) != 10 {
t.Error("Generator returned invalid length")
}
if !isLetter(s) {
t.Errorf("Generator returned unexpected character: %s", s)
}
}
}
func TestCryptoUint64(t *testing.T) {
localMin := uint64(0xFFFFFFFFFFFFFFFF)
localMax := uint64(0)
for i := 0; i < 10000; i++ {
r, err := CryptoUint64()
if err != nil {
t.Fatal(err)
}
if r < localMin {
localMin = r
}
if r > localMax {
localMax = r
}
}
if localMin > 0x1000000000000000 {
t.Error("Value around lower boundary was not generated")
}
if localMax < 0xF000000000000000 {
t.Error("Value around upper boundary was not generated")
}
}