GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
(n int)
| 413 | // number generator fails to function correctly, in which |
| 414 | // case the caller should not continue. |
| 415 | func GenerateRandomBytes(n int) ([]byte, error) { |
| 416 | b := make([]byte, n) |
| 417 | _, err := rand.Read(b) |
| 418 | // Note that err == nil only if we read len(b) bytes. |
| 419 | if err != nil { |
| 420 | return nil, err |
| 421 | } |
| 422 | |
| 423 | return b, nil |
| 424 | } |
| 425 | |
| 426 | // GenerateRandomString returns a securely generated random string. |
| 427 | // It will return an error if the system's secure random |
no test coverage detected