Skip to content

Commit ea2f747

Browse files
lpcoxCopilot
andauthored
Update internal/strutil/random_hex.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fb1edff commit ea2f747

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

internal/strutil/random_hex.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
// RandomHex returns a hex-encoded string of n cryptographically random bytes.
1010
// The returned string has length 2*n.
1111
func RandomHex(n int) (string, error) {
12+
if n < 0 {
13+
return "", fmt.Errorf("failed to generate random bytes: negative size %d", n)
14+
}
1215
b := make([]byte, n)
1316
if _, err := rand.Read(b); err != nil {
1417
return "", fmt.Errorf("failed to generate %d random bytes: %w", n, err)

0 commit comments

Comments
 (0)