-
Notifications
You must be signed in to change notification settings - Fork 19
/
rand.go
64 lines (57 loc) · 969 Bytes
/
rand.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package log4shell
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func randBool() bool {
return rand.Int63()%2 == 0 // #nosec
}
func randString(n int) string {
str := make([]rune, n)
for i := 0; i < n; i++ {
s := ' ' + 1 + rand.Intn(90) // #nosec
switch {
case s >= '0' && s <= '9':
case s >= 'A' && s <= 'Z':
case s >= 'a' && s <= 'z':
case isValidSymbol(s):
default:
i--
continue
}
str[i] = rune(s)
}
return string(str)
}
func isValidSymbol(s int) bool {
switch s {
case '(', ')':
case '*', '.':
case '$', '_':
case '[', ']':
case '@', '=':
default:
return false
}
return true
}
func randSecret() string {
const n = 8
str := make([]rune, n)
for i := 0; i < n; i++ {
s := ' ' + 1 + rand.Intn(90) // #nosec
switch {
case s >= '0' && s <= '9':
case s >= 'A' && s <= 'Z':
case s >= 'a' && s <= 'z':
default:
i--
continue
}
str[i] = rune(s)
}
return string(str)
}