Skip to content

Commit

Permalink
generator: use math/rand/v2 to get random bytes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Butusov <andrey@nspcc.io>
  • Loading branch information
End-rey committed Aug 30, 2024
1 parent 91060a3 commit f4c86ad
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/datagen/generator.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package datagen

import (
"crypto/rand"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"math/rand/v2"
"time"

"github.com/dop251/goja"
"go.k6.io/k6/js/modules"
Expand Down Expand Up @@ -58,10 +60,12 @@ func (g *Generator) nextSlice() []byte {
if g.buf == nil {
// Allocate buffer with extra tail for sliding and populate it with random bytes
g.buf = make([]byte, g.size+TailSize)
_, err := rand.Read(g.buf)
if err != nil {
panic(err)
}

var seed [32]byte
binary.LittleEndian.PutUint64(seed[:], uint64(time.Now().UnixNano()))
chaCha8 := rand.NewChaCha8(seed)
// nolint:errcheck
chaCha8.Read(g.buf) // Per docs, err is always nil here

Check failure on line 68 in internal/datagen/generator.go

View workflow job for this annotation

GitHub Actions / Tests (ubuntu-22.04, 1.22)

chaCha8.Read undefined (type *"math/rand/v2".ChaCha8 has no field or method Read)
}

result := g.buf[g.offset : g.offset+g.size]
Expand Down

0 comments on commit f4c86ad

Please sign in to comment.