randomString 生成随机字符串(使用 crypto/rand)
(n int)
| 1018 | |
| 1019 | // randomString 生成随机字符串(使用 crypto/rand) |
| 1020 | func randomString(n int) string { |
| 1021 | b := make([]byte, n) |
| 1022 | if _, err := rand.Read(b); err != nil { |
| 1023 | // fallback to timestamp-based |
| 1024 | for i := range b { |
| 1025 | b[i] = byte('a' + (time.Now().UnixNano() % 26)) |
| 1026 | } |
| 1027 | return string(b) |
| 1028 | } |
| 1029 | return hex.EncodeToString(b)[:n] |
| 1030 | } |
| 1031 | |
| 1032 | // isExcludedCommand 检查命令是否在排除列表中 |
| 1033 | func (ls *LocalSandbox) isExcludedCommand(cmd string) bool { |