Browse Source

Switch to rand/v2

tags/v2.1.10^2^2
9seconds 2 months ago
parent
commit
a0aabf2391

+ 1
- 1
events/event_stream.go View File

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

+ 2
- 2
mtglib/internal/faketls/conn.go View File

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

+ 2
- 2
mtglib/internal/faketls/conn_test.go View File

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

+ 2
- 2
mtglib/internal/faketls/welcome.go View File

6
 	"crypto/sha256"
6
 	"crypto/sha256"
7
 	"encoding/binary"
7
 	"encoding/binary"
8
 	"io"
8
 	"io"
9
-	mrand "math/rand"
9
+	mrand "math/rand/v2"
10
 
10
 
11
 	"github.com/9seconds/mtg/v2/mtglib/internal/faketls/record"
11
 	"github.com/9seconds/mtg/v2/mtglib/internal/faketls/record"
12
 	"golang.org/x/crypto/curve25519"
12
 	"golang.org/x/crypto/curve25519"
36
 	rec.Type = record.TypeApplicationData
36
 	rec.Type = record.TypeApplicationData
37
 	rec.Version = record.Version12
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
 		panic(err)
40
 		panic(err)
41
 	}
41
 	}
42
 
42
 

+ 1
- 1
mtglib/internal/faketls/welcome_test.go View File

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

+ 2
- 2
network/load_balanced_socks5.go View File

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

+ 1
- 1
network/network.go View File

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

Loading…
Cancel
Save