1 |
package crypto
|
|
2 |
|
|
3 |
import "crypto/rand" |
|
4 |
|
|
5 |
// GenerateNonce creates a new random nonce.
|
|
6 |
func GenerateNonce(size int) ([]byte, error) { |
1,000,001✔ |
7 |
nonce := make([]byte, size) |
1,000,001✔ |
8 |
_, err := rand.Read(nonce) |
1,000,001✔ |
9 |
if err != nil { |
1,000,001✔ |
10 |
return nil, err |
× |
11 |
} |
× |
12 |
return nonce, nil |
1,000,001✔ |
13 |
} |