Skip to content

Commit 8635651

Browse files
committed
fix: lint
1 parent 2329787 commit 8635651

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

crypto/rand/rand_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func BenchmarkGenerateRandomString(b *testing.B) {
9595
r := randz.NewReader(randz.WithNewReaderOptionRandomReader(mrand.New(mrand.NewSource(0))))
9696
buf := make([]byte, 128)
9797

98-
for i := 0; i < b.N; i++ {
98+
for range b.N {
9999
_, _ = r.Read(buf)
100100
}
101101
})
@@ -104,7 +104,7 @@ func BenchmarkGenerateRandomString(b *testing.B) {
104104
r := randz.NewReader(randz.WithNewReaderOptionRandomReader(crypto_rand.Reader))
105105
buf := make([]byte, 128)
106106

107-
for i := 0; i < b.N; i++ {
107+
for range b.N {
108108
_, _ = r.Read(buf)
109109
}
110110
})

database/sql/rows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func getStructTags(structType reflect.Type, structTag string) []string {
169169
}
170170

171171
tags := make([]string, structType.NumField())
172-
for i := 0; structType.NumField() > i; i++ {
172+
for i := range structType.NumField() {
173173
rawTag := structType.Field(i).Tag.Get(structTag)
174174
tags[i] = strings.Split(rawTag, ",")[0]
175175
}

jose/jwa/sign_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ var signTestCases = map[string]struct {
500500
func TestJWSAlgorithm_Sign(t *testing.T) {
501501
t.Parallel()
502502
for name, testCase := range signTestCases {
503-
t, name, testCase := t, name, testCase
504503
t.Run(name, func(t *testing.T) {
505504
t.Parallel()
506505
actual, err := jwa.JWS(testCase.alg).Sign(testCase.key, testCase.signingInput)

jose/jwa/verify_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ var verifyTestCases = map[string]struct {
435435
func TestJWSAlgorithm_Verify(t *testing.T) {
436436
t.Parallel()
437437
for name, testCase := range verifyTestCases {
438-
t, name, testCase := t, name, testCase
439438
t.Run(name, func(t *testing.T) {
440439
t.Parallel()
441440
testCase.errHandler(t, jwa.JWS(testCase.alg).Verify(testCase.key, testCase.signingInput, testCase.signatureEncoded))

jose/jwk/jwk.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"fmt"
1313
"io"
14+
"math"
1415
"math/big"
1516
"net/http"
1617
"time"
@@ -23,6 +24,7 @@ var (
2324
ErrCurveNotSupported = errors.New("jwk: specified curve parameter is not supported")
2425
ErrKeyIsNotForAlgorithm = errors.New("jwk: key is not for algorithm")
2526
ErrResponseIsNotCacheable = errors.New("jwk: response is not cacheable")
27+
ErrInvalidKey = errors.New("jwk: invalid key")
2628
)
2729

2830
// ref. JSON Web Key (JWK) https://www.rfc-editor.org/rfc/rfc7517
@@ -394,19 +396,25 @@ func (jwk *JSONWebKey) EncodeRSAPublicKey(key *rsa.PublicKey, opts ...JSONWebKey
394396
}
395397

396398
func (jwk *JSONWebKey) DecodeRSAPublicKey() (*rsa.PublicKey, error) {
397-
n, err := base64.RawURLEncoding.DecodeString(jwk.N)
399+
nByte, err := base64.RawURLEncoding.DecodeString(jwk.N)
398400
if err != nil {
399401
return nil, fmt.Errorf("base64.RawURLEncoding.DecodeString: JSONWebKey.N=%s: %w", jwk.N, err)
400402
}
403+
n := big.NewInt(0).SetBytes(nByte)
401404

402-
e, err := base64.RawURLEncoding.DecodeString(jwk.E)
405+
eByte, err := base64.RawURLEncoding.DecodeString(jwk.E)
403406
if err != nil {
404407
return nil, fmt.Errorf("base64.RawURLEncoding.DecodeString: JSONWebKey.E=%s: %w", jwk.E, err)
405408
}
409+
eBigInt := big.NewInt(0).SetBytes(eByte)
410+
if eBigInt.Uint64() > math.MaxInt {
411+
return nil, fmt.Errorf("e=%d: %w", eBigInt.Uint64(), ErrInvalidKey)
412+
}
413+
e := int(eBigInt.Uint64())
406414

407415
return &rsa.PublicKey{
408-
N: big.NewInt(0).SetBytes(n),
409-
E: int(big.NewInt(0).SetBytes(e).Uint64()),
416+
N: n,
417+
E: e,
410418
}, nil
411419
}
412420

math/rand/rand.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ import (
55
"time"
66
)
77

8-
func Range(min, max int) int {
8+
func Range(minValue, maxValue int) int {
99
//nolint:gosec
10-
return rand.Intn(max-min+1) + min
10+
return rand.Intn(maxValue-minValue+1) + minValue
1111
}
1212

13-
func RangeRand(r *rand.Rand, min, max int) int {
14-
return r.Intn(max-min+1) + min
13+
func RangeRand(r *rand.Rand, minValue, maxValue int) int {
14+
return r.Intn(maxValue-minValue+1) + minValue
1515
}
1616

17-
func Range31(min, max int32) int32 {
17+
func Range31(minValue, maxValue int32) int32 {
1818
//nolint:gosec
19-
return rand.Int31n(max-min+1) + min
19+
return rand.Int31n(maxValue-minValue+1) + minValue
2020
}
2121

22-
func Range31Rand(r *rand.Rand, min, max int32) int32 {
23-
return r.Int31n(max-min+1) + min
22+
func Range31Rand(r *rand.Rand, minValue, maxValue int32) int32 {
23+
return r.Int31n(maxValue-minValue+1) + minValue
2424
}
2525

26-
func Range63(min, max int64) int64 {
26+
func Range63(minValue, maxValue int64) int64 {
2727
//nolint:gosec
28-
return rand.Int63n(max-min+1) + min
28+
return rand.Int63n(maxValue-minValue+1) + minValue
2929
}
3030

31-
func Range63Rand(r *rand.Rand, min, max int64) int64 {
32-
return r.Int63n(max-min+1) + min
31+
func Range63Rand(r *rand.Rand, minValue, maxValue int64) int64 {
32+
return r.Int63n(maxValue-minValue+1) + minValue
3333
}
3434

35-
func RangeDuration(min, max time.Duration) time.Duration {
35+
func RangeDuration(minValue, maxValue time.Duration) time.Duration {
3636
//nolint:gosec
37-
return time.Duration(rand.Int63n(int64(max)-int64(min)+1) + int64(min))
37+
return time.Duration(rand.Int63n(int64(maxValue)-int64(minValue)+1) + int64(minValue))
3838
}
3939

40-
func RangeDurationRand(r *rand.Rand, min, max time.Duration) time.Duration {
40+
func RangeDurationRand(r *rand.Rand, minValue, maxValue time.Duration) time.Duration {
4141
//nolint:gosec
42-
return time.Duration(r.Int63n(int64(max)-int64(min)+1) + int64(min))
42+
return time.Duration(r.Int63n(int64(maxValue)-int64(minValue)+1) + int64(minValue))
4343
}

strings/mask_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func TestMaskPrefix(t *testing.T) {
2626
{"mask 4", args{"abcd", "*", 4}, "****"},
2727
}
2828
for _, tt := range tests {
29-
tt := tt
3029
t.Run(tt.name, func(t *testing.T) {
3130
t.Parallel()
3231
if got := stringz.MaskPrefix(tt.args.s, tt.args.mask, tt.args.unmaskSuffix); got != tt.want {
@@ -56,7 +55,6 @@ func TestMaskSuffix(t *testing.T) {
5655
{"mask 4", args{"abcd", "*", 4}, "abcd"},
5756
}
5857
for _, tt := range tests {
59-
tt := tt
6058
t.Run(tt.name, func(t *testing.T) {
6159
t.Parallel()
6260
if got := stringz.MaskSuffix(tt.args.s, tt.args.mask, tt.args.unmaskPrefix); got != tt.want {

sync/once_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func TestOnce_Do(t *testing.T) {
4949
actual := 0
5050
const expect = 10
5151
for i := 1; i <= 10; i++ {
52-
i := i
5352
if err := once.Do(func() error {
5453
actual = i
5554
return io.EOF // any error

0 commit comments

Comments
 (0)