[#161] *: Do not use math/rand.Read()

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-09-08 17:15:08 +03:00
parent aa12d8c6a6
commit 49ad985cad
15 changed files with 24 additions and 22 deletions

View file

@ -2,9 +2,9 @@ package checksum
import ( import (
"bytes" "bytes"
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"math/rand"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
) )

View file

@ -1,8 +1,8 @@
package checksumtest package checksumtest
import ( import (
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"math/rand"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum"
) )
@ -11,7 +11,7 @@ import (
func Checksum() checksum.Checksum { func Checksum() checksum.Checksum {
var cs [sha256.Size]byte var cs [sha256.Size]byte
rand.Read(cs[:]) _, _ = rand.Read(cs[:])
var x checksum.Checksum var x checksum.Checksum

View file

@ -1,8 +1,8 @@
package cid_test package cid_test
import ( import (
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"math/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"

View file

@ -1,8 +1,8 @@
package cidtest package cidtest
import ( import (
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"math/rand"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
) )
@ -11,7 +11,7 @@ import (
func ID() cid.ID { func ID() cid.ID {
checksum := [sha256.Size]byte{} checksum := [sha256.Size]byte{}
rand.Read(checksum[:]) _, _ = rand.Read(checksum[:])
return IDWithChecksum(checksum) return IDWithChecksum(checksum)
} }

View file

@ -1,7 +1,7 @@
package frostfscrypto_test package frostfscrypto_test
import ( import (
"math/rand" "crypto/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"

View file

@ -2,7 +2,7 @@ package eacltest
import ( import (
"bytes" "bytes"
"math/rand" "crypto/rand"
"testing" "testing"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"

View file

@ -1,7 +1,7 @@
package eacl package eacl
import ( import (
"math/rand" "crypto/rand"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"

View file

@ -1,9 +1,10 @@
package netmap package netmap
import ( import (
"crypto/rand"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math/rand" mrand "math/rand"
"sort" "sort"
"strconv" "strconv"
"testing" "testing"
@ -28,10 +29,10 @@ func BenchmarkHRWSort(b *testing.B) {
node.SetPublicKey(key) node.SetPublicKey(key)
vectors[i] = nodes{node} vectors[i] = nodes{node}
weights[i] = float64(rand.Uint32()%10) / 10.0 weights[i] = float64(mrand.Uint32()%10) / 10.0
} }
pivot := rand.Uint64() pivot := mrand.Uint64()
b.Run("sort by index, no weight", func(b *testing.B) { b.Run("sort by index, no weight", func(b *testing.B) {
realNodes := make([]nodes, netmapSize) realNodes := make([]nodes, netmapSize)
b.ResetTimer() b.ResetTimer()

View file

@ -1,7 +1,7 @@
package netmaptest package netmaptest
import ( import (
"math/rand" "crypto/rand"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
) )
@ -70,7 +70,7 @@ func NetworkInfo() (x netmap.NetworkInfo) {
// NodeInfo returns random netmap.NodeInfo. // NodeInfo returns random netmap.NodeInfo.
func NodeInfo() (x netmap.NodeInfo) { func NodeInfo() (x netmap.NodeInfo) {
key := make([]byte, 33) key := make([]byte, 33)
rand.Read(key) _, _ = rand.Read(key)
x.SetPublicKey(key) x.SetPublicKey(key)
x.SetNetworkEndpoints("1", "2", "3") x.SetNetworkEndpoints("1", "2", "3")

View file

@ -1,10 +1,10 @@
package ns package ns
import ( import (
"crypto/rand"
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"math/rand"
"strings" "strings"
"testing" "testing"

View file

@ -1,8 +1,8 @@
package oidtest package oidtest
import ( import (
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"math/rand"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
@ -12,7 +12,7 @@ import (
func ID() oid.ID { func ID() oid.ID {
checksum := [sha256.Size]byte{} checksum := [sha256.Size]byte{}
rand.Read(checksum[:]) _, _ = rand.Read(checksum[:])
return idWithChecksum(checksum) return idWithChecksum(checksum)
} }

View file

@ -1,8 +1,8 @@
package object_test package object_test
import ( import (
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"math/rand"
"testing" "testing"
v2object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" v2object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"

View file

@ -1,8 +1,8 @@
package object package object
import ( import (
"crypto/rand"
"crypto/sha256" "crypto/sha256"
"math/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone"

View file

@ -1,9 +1,10 @@
package session_test package session_test
import ( import (
"crypto/rand"
"fmt" "fmt"
"math" "math"
"math/rand" mrand "math/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
@ -396,7 +397,7 @@ func TestContainer_AppliedTo(t *testing.T) {
func TestContainer_InvalidAt(t *testing.T) { func TestContainer_InvalidAt(t *testing.T) {
var x session.Container var x session.Container
nbf := rand.Uint64() nbf := mrand.Uint64()
if nbf == math.MaxUint64 { if nbf == math.MaxUint64 {
nbf-- nbf--
} }

View file

@ -1,7 +1,7 @@
package user_test package user_test
import ( import (
"math/rand" "crypto/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"