Parcourir la source

Switch to rand/v2

tags/v2.1.10^2^2
9seconds il y a 2 mois
Parent
révision
a0aabf2391

+ 1
- 1
events/event_stream.go Voir le fichier

@@ -2,7 +2,7 @@ package events
2 2
 
3 3
 import (
4 4
 	"context"
5
-	"math/rand"
5
+	"math/rand/v2"
6 6
 	"runtime"
7 7
 
8 8
 	"github.com/9seconds/mtg/v2/mtglib"

+ 2
- 2
mtglib/internal/faketls/conn.go Voir le fichier

@@ -3,7 +3,7 @@ package faketls
3 3
 import (
4 4
 	"bytes"
5 5
 	"fmt"
6
-	"math/rand"
6
+	"math/rand/v2"
7 7
 
8 8
 	"github.com/9seconds/mtg/v2/essentials"
9 9
 	"github.com/9seconds/mtg/v2/mtglib/internal/faketls/record"
@@ -53,7 +53,7 @@ func (c *Conn) Write(p []byte) (int, error) {
53 53
 	lenP := len(p)
54 54
 
55 55
 	for len(p) > 0 {
56
-		chunkSize := rand.Intn(record.TLSMaxRecordSize)
56
+		chunkSize := rand.IntN(record.TLSMaxRecordSize)
57 57
 		if chunkSize > len(p) || chunkSize == 0 {
58 58
 			chunkSize = len(p)
59 59
 		}

+ 2
- 2
mtglib/internal/faketls/conn_test.go Voir le fichier

@@ -2,9 +2,9 @@ package faketls_test
2 2
 
3 3
 import (
4 4
 	"bytes"
5
+	"crypto/rand"
5 6
 	"errors"
6 7
 	"io"
7
-	"math/rand"
8 8
 	"testing"
9 9
 
10 10
 	"github.com/9seconds/mtg/v2/internal/testlib"
@@ -123,7 +123,7 @@ func (suite *ConnTestSuite) TestWrite() {
123 123
 	suite.connMock.On("Write", mock.Anything).Return(0, nil)
124 124
 
125 125
 	dataToRec := make([]byte, record.TLSMaxRecordSize*2)
126
-	rand.Read(dataToRec) //nolint: staticcheck
126
+	rand.Read(dataToRec) //nolint: staticcheck, errcheck
127 127
 
128 128
 	n, err := suite.c.Write(dataToRec)
129 129
 	suite.NoError(err)

+ 2
- 2
mtglib/internal/faketls/welcome.go Voir le fichier

@@ -6,7 +6,7 @@ import (
6 6
 	"crypto/sha256"
7 7
 	"encoding/binary"
8 8
 	"io"
9
-	mrand "math/rand"
9
+	mrand "math/rand/v2"
10 10
 
11 11
 	"github.com/9seconds/mtg/v2/mtglib/internal/faketls/record"
12 12
 	"golang.org/x/crypto/curve25519"
@@ -36,7 +36,7 @@ func SendWelcomePacket(writer io.Writer, secret []byte, clientHello ClientHello)
36 36
 	rec.Type = record.TypeApplicationData
37 37
 	rec.Version = record.Version12
38 38
 
39
-	if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.Intn(3092))); err != nil {
39
+	if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.IntN(3092))); err != nil {
40 40
 		panic(err)
41 41
 	}
42 42
 

+ 1
- 1
mtglib/internal/faketls/welcome_test.go Voir le fichier

@@ -3,8 +3,8 @@ package faketls_test
3 3
 import (
4 4
 	"bytes"
5 5
 	"crypto/hmac"
6
+	"crypto/rand"
6 7
 	"crypto/sha256"
7
-	"math/rand"
8 8
 	"testing"
9 9
 	"time"
10 10
 

+ 2
- 2
network/load_balanced_socks5.go Voir le fichier

@@ -3,7 +3,7 @@ package network
3 3
 import (
4 4
 	"context"
5 5
 	"fmt"
6
-	"math/rand"
6
+	"math/rand/v2"
7 7
 	"net/url"
8 8
 
9 9
 	"github.com/9seconds/mtg/v2/essentials"
@@ -19,7 +19,7 @@ func (l loadBalancedSocks5Dialer) Dial(network, address string) (essentials.Conn
19 19
 
20 20
 func (l loadBalancedSocks5Dialer) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) {
21 21
 	length := len(l.dialers)
22
-	start := rand.Intn(length)
22
+	start := rand.IntN(length)
23 23
 	moved := false
24 24
 
25 25
 	for i := start; i != start || !moved; i = (i + 1) % length {

+ 1
- 1
network/network.go Voir le fichier

@@ -3,7 +3,7 @@ package network
3 3
 import (
4 4
 	"context"
5 5
 	"fmt"
6
-	"math/rand"
6
+	"math/rand/v2"
7 7
 	"net"
8 8
 	"net/http"
9 9
 	"sync"

Chargement…
Annuler
Enregistrer