mirror of
https://github.com/r-smith/deceptifeed.git
synced 2025-10-23 16:24:00 +00:00
Update rand.Read error handling
As of Go 1.24, rand.Read is guaranteed to never return an error. This change removes the error check and the associated fallback function when calling rand.Read.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"fmt"
|
||||||
prng "math/rand/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -80,16 +79,10 @@ func newUUIDv4() string {
|
|||||||
// overwritten to indicate version 4 and the variant (the format of the
|
// overwritten to indicate version 4 and the variant (the format of the
|
||||||
// UUID).
|
// UUID).
|
||||||
|
|
||||||
// Get 16 random bytes.
|
// Get 16 random bytes. crypto/rand.Read is guaranteed to never return an
|
||||||
|
// error (as of Go 1.24).
|
||||||
var b = [16]byte{}
|
var b = [16]byte{}
|
||||||
_, err := rand.Read(b[:])
|
rand.Read(b[:])
|
||||||
if err != nil {
|
|
||||||
// Fall back to PRNG if the OS random number generator call fails.
|
|
||||||
for i := range b {
|
|
||||||
// Go's math/rand/v2 package is imported as `prng`.
|
|
||||||
b[i] = byte(prng.Int())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overwrite the version bits with 0b0100 (UUID version 4).
|
// Overwrite the version bits with 0b0100 (UUID version 4).
|
||||||
b[6] = (b[6] & 0x0f) | 0x40
|
b[6] = (b[6] & 0x0f) | 0x40
|
||||||
|
Reference in New Issue
Block a user