Remove math.rand/Read #161

Merged
fyrchik merged 2 commits from fyrchik/frostfs-sdk-go:fix-mathrand into master 2024-09-04 19:51:15 +00:00
16 changed files with 25 additions and 23 deletions

View file

@ -25,7 +25,7 @@ linters-settings:
# report about shadowed variables
check-shadowing: false
staticcheck:
checks: ["all", "-SA1019"] # TODO Enable SA1019 after deprecated warning are fixed.
checks: ["all"]
funlen:
lines: 80 # default 60
statements: 60 # default 40

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,9 +1,10 @@
package netmap
import (
"crypto/rand"
"encoding/binary"
"fmt"
"math/rand"
mrand "math/rand"
"sort"
"strconv"
"testing"
@ -28,10 +29,10 @@ func BenchmarkHRWSort(b *testing.B) {
node.SetPublicKey(key)
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) {
realNodes := make([]nodes, netmapSize)
b.ResetTimer()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,9 +1,10 @@
package session_test
import (
"crypto/rand"
"fmt"
"math"
"math/rand"
mrand "math/rand"
"testing"
"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) {
var x session.Container
nbf := rand.Uint64()
nbf := mrand.Uint64()
if nbf == math.MaxUint64 {
nbf--
}

View file

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