randString generates a random string with length n.
(n int)
| 248 | |
| 249 | // randString generates a random string with length n. |
| 250 | func randString(n int) string { |
| 251 | b := make([]byte, n) |
| 252 | _, err := rand.Reader.Read(b) |
| 253 | if err != nil { |
| 254 | panic(fmt.Sprintf("failed to generate rand bytes: %v", err)) |
| 255 | } |
| 256 | |
| 257 | s := strings.ToValidUTF8(string(b), "_") |
| 258 | s = strings.ReplaceAll(s, "\x00", "_") |
| 259 | if len(s) > n { |
| 260 | return s[:n] |
| 261 | } |
| 262 | if len(s) < n { |
| 263 | // Pad with = |
| 264 | extra := n - len(s) |
| 265 | return s + strings.Repeat("=", extra) |
| 266 | } |
| 267 | return s |
| 268 | } |
| 269 | |
| 270 | // randInt returns a randomly generated integer between [0, max). |
| 271 | func randInt(max int) int { |
no test coverage detected
searching dependent graphs…