Skip to content

Commit 0eef781

Browse files
committed
chore: replace ioutil with io and os (golang-jwt#198)
1 parent 3558b63 commit 0eef781

File tree

9 files changed

+37
-37
lines changed

9 files changed

+37
-37
lines changed

cmd/jwt/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"flag"
1212
"fmt"
1313
"io"
14-
"io/ioutil"
1514
"os"
1615
"regexp"
1716
"sort"
@@ -91,7 +90,7 @@ func loadData(p string) ([]byte, error) {
9190
return nil, err
9291
}
9392
}
94-
return ioutil.ReadAll(rdr)
93+
return io.ReadAll(rdr)
9594
}
9695

9796
// Print a json object in accordance with the prophecy (or the command line options)

ecdsa_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package jwt_test
22

33
import (
44
"crypto/ecdsa"
5-
"io/ioutil"
5+
"os"
66
"strings"
77
"testing"
88

@@ -55,7 +55,7 @@ func TestECDSAVerify(t *testing.T) {
5555
for _, data := range ecdsaTestData {
5656
var err error
5757

58-
key, _ := ioutil.ReadFile(data.keys["public"])
58+
key, _ := os.ReadFile(data.keys["public"])
5959

6060
var ecdsaKey *ecdsa.PublicKey
6161
if ecdsaKey, err = jwt.ParseECPublicKeyFromPEM(key); err != nil {
@@ -78,7 +78,7 @@ func TestECDSAVerify(t *testing.T) {
7878
func TestECDSASign(t *testing.T) {
7979
for _, data := range ecdsaTestData {
8080
var err error
81-
key, _ := ioutil.ReadFile(data.keys["private"])
81+
key, _ := os.ReadFile(data.keys["private"])
8282

8383
var ecdsaKey *ecdsa.PrivateKey
8484
if ecdsaKey, err = jwt.ParseECPrivateKeyFromPEM(key); err != nil {
@@ -108,7 +108,7 @@ func TestECDSASign(t *testing.T) {
108108

109109
func BenchmarkECDSAParsing(b *testing.B) {
110110
for _, data := range ecdsaTestData {
111-
key, _ := ioutil.ReadFile(data.keys["private"])
111+
key, _ := os.ReadFile(data.keys["private"])
112112

113113
b.Run(data.name, func(b *testing.B) {
114114
b.ReportAllocs()
@@ -126,7 +126,7 @@ func BenchmarkECDSAParsing(b *testing.B) {
126126

127127
func BenchmarkECDSASigning(b *testing.B) {
128128
for _, data := range ecdsaTestData {
129-
key, _ := ioutil.ReadFile(data.keys["private"])
129+
key, _ := os.ReadFile(data.keys["private"])
130130

131131
ecdsaKey, err := jwt.ParseECPrivateKeyFromPEM(key)
132132
if err != nil {

ed25519_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package jwt_test
22

33
import (
4-
"io/ioutil"
4+
"os"
55
"strings"
66
"testing"
77

@@ -38,7 +38,7 @@ func TestEd25519Verify(t *testing.T) {
3838
for _, data := range ed25519TestData {
3939
var err error
4040

41-
key, _ := ioutil.ReadFile(data.keys["public"])
41+
key, _ := os.ReadFile(data.keys["public"])
4242

4343
ed25519Key, err := jwt.ParseEdPublicKeyFromPEM(key)
4444
if err != nil {
@@ -62,7 +62,7 @@ func TestEd25519Verify(t *testing.T) {
6262
func TestEd25519Sign(t *testing.T) {
6363
for _, data := range ed25519TestData {
6464
var err error
65-
key, _ := ioutil.ReadFile(data.keys["private"])
65+
key, _ := os.ReadFile(data.keys["private"])
6666

6767
ed25519Key, err := jwt.ParseEdPrivateKeyFromPEM(key)
6868
if err != nil {

hmac_example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package jwt_test
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"os"
66
"time"
77

88
"github.com/golang-jwt/jwt/v4"
@@ -15,7 +15,7 @@ var hmacSampleSecret []byte
1515

1616
func init() {
1717
// Load sample key data
18-
if keyData, e := ioutil.ReadFile("test/hmacTestKey"); e == nil {
18+
if keyData, e := os.ReadFile("test/hmacTestKey"); e == nil {
1919
hmacSampleSecret = keyData
2020
} else {
2121
panic(e)

hmac_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package jwt_test
22

33
import (
4-
"io/ioutil"
4+
"os"
55
"strings"
66
"testing"
77

@@ -46,7 +46,7 @@ var hmacTestData = []struct {
4646
}
4747

4848
// Sample data from http://tools.ietf.org/html/draft-jones-json-web-signature-04#appendix-A.1
49-
var hmacTestKey, _ = ioutil.ReadFile("test/hmacTestKey")
49+
var hmacTestKey, _ = os.ReadFile("test/hmacTestKey")
5050

5151
func TestHMACVerify(t *testing.T) {
5252
for _, data := range hmacTestData {

http_example_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"crypto/rsa"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"log"
1312
"net"
1413
"net/http"
1514
"net/url"
15+
"os"
1616
"strings"
1717
"time"
1818

@@ -34,13 +34,13 @@ var (
3434

3535
// read the key files before starting http handlers
3636
func init() {
37-
signBytes, err := ioutil.ReadFile(privKeyPath)
37+
signBytes, err := os.ReadFile(privKeyPath)
3838
fatal(err)
3939

4040
signKey, err = jwt.ParseRSAPrivateKeyFromPEM(signBytes)
4141
fatal(err)
4242

43-
verifyBytes, err := ioutil.ReadFile(pubKeyPath)
43+
verifyBytes, err := os.ReadFile(pubKeyPath)
4444
fatal(err)
4545

4646
verifyKey, err = jwt.ParseRSAPublicKeyFromPEM(verifyBytes)

rsa_pss_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
//go:build go1.4
12
// +build go1.4
23

34
package jwt_test
45

56
import (
67
"crypto/rsa"
7-
"io/ioutil"
8+
"os"
89
"strings"
910
"testing"
1011
"time"
@@ -53,7 +54,7 @@ var rsaPSSTestData = []struct {
5354
func TestRSAPSSVerify(t *testing.T) {
5455
var err error
5556

56-
key, _ := ioutil.ReadFile("test/sample_key.pub")
57+
key, _ := os.ReadFile("test/sample_key.pub")
5758
var rsaPSSKey *rsa.PublicKey
5859
if rsaPSSKey, err = jwt.ParseRSAPublicKeyFromPEM(key); err != nil {
5960
t.Errorf("Unable to parse RSA public key: %v", err)
@@ -76,7 +77,7 @@ func TestRSAPSSVerify(t *testing.T) {
7677
func TestRSAPSSSign(t *testing.T) {
7778
var err error
7879

79-
key, _ := ioutil.ReadFile("test/sample_key")
80+
key, _ := os.ReadFile("test/sample_key")
8081
var rsaPSSKey *rsa.PrivateKey
8182
if rsaPSSKey, err = jwt.ParseRSAPrivateKeyFromPEM(key); err != nil {
8283
t.Errorf("Unable to parse RSA private key: %v", err)

rsa_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"crypto/rsa"
77
"crypto/x509"
88
"encoding/pem"
9-
"io/ioutil"
9+
"os"
1010
"strings"
1111
"testing"
1212

@@ -51,7 +51,7 @@ var rsaTestData = []struct {
5151
}
5252

5353
func TestRSAVerify(t *testing.T) {
54-
keyData, _ := ioutil.ReadFile("test/sample_key.pub")
54+
keyData, _ := os.ReadFile("test/sample_key.pub")
5555
key, _ := jwt.ParseRSAPublicKeyFromPEM(keyData)
5656

5757
for _, data := range rsaTestData {
@@ -69,7 +69,7 @@ func TestRSAVerify(t *testing.T) {
6969
}
7070

7171
func TestRSASign(t *testing.T) {
72-
keyData, _ := ioutil.ReadFile("test/sample_key")
72+
keyData, _ := os.ReadFile("test/sample_key")
7373
key, _ := jwt.ParseRSAPrivateKeyFromPEM(keyData)
7474

7575
for _, data := range rsaTestData {
@@ -88,7 +88,7 @@ func TestRSASign(t *testing.T) {
8888
}
8989

9090
func TestRSAVerifyWithPreParsedPrivateKey(t *testing.T) {
91-
key, _ := ioutil.ReadFile("test/sample_key.pub")
91+
key, _ := os.ReadFile("test/sample_key.pub")
9292
parsedKey, err := jwt.ParseRSAPublicKeyFromPEM(key)
9393
if err != nil {
9494
t.Fatal(err)
@@ -102,7 +102,7 @@ func TestRSAVerifyWithPreParsedPrivateKey(t *testing.T) {
102102
}
103103

104104
func TestRSAWithPreParsedPrivateKey(t *testing.T) {
105-
key, _ := ioutil.ReadFile("test/sample_key")
105+
key, _ := os.ReadFile("test/sample_key")
106106
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
107107
if err != nil {
108108
t.Fatal(err)
@@ -119,9 +119,9 @@ func TestRSAWithPreParsedPrivateKey(t *testing.T) {
119119
}
120120

121121
func TestRSAKeyParsing(t *testing.T) {
122-
key, _ := ioutil.ReadFile("test/sample_key")
123-
secureKey, _ := ioutil.ReadFile("test/privateSecure.pem")
124-
pubKey, _ := ioutil.ReadFile("test/sample_key.pub")
122+
key, _ := os.ReadFile("test/sample_key")
123+
secureKey, _ := os.ReadFile("test/privateSecure.pem")
124+
pubKey, _ := os.ReadFile("test/sample_key.pub")
125125
badKey := []byte("All your base are belong to key")
126126

127127
// Test parsePrivateKey
@@ -180,7 +180,7 @@ func TestRSAParsePublicKeyFromPEM_PKCS1(t *testing.T) {
180180
}
181181

182182
func BenchmarkRSAParsing(b *testing.B) {
183-
key, _ := ioutil.ReadFile("test/sample_key")
183+
key, _ := os.ReadFile("test/sample_key")
184184

185185
b.ReportAllocs()
186186
b.ResetTimer()
@@ -194,7 +194,7 @@ func BenchmarkRSAParsing(b *testing.B) {
194194
}
195195

196196
func BenchmarkRS256Signing(b *testing.B) {
197-
key, _ := ioutil.ReadFile("test/sample_key")
197+
key, _ := os.ReadFile("test/sample_key")
198198
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
199199
if err != nil {
200200
b.Fatal(err)
@@ -204,7 +204,7 @@ func BenchmarkRS256Signing(b *testing.B) {
204204
}
205205

206206
func BenchmarkRS384Signing(b *testing.B) {
207-
key, _ := ioutil.ReadFile("test/sample_key")
207+
key, _ := os.ReadFile("test/sample_key")
208208
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
209209
if err != nil {
210210
b.Fatal(err)
@@ -214,7 +214,7 @@ func BenchmarkRS384Signing(b *testing.B) {
214214
}
215215

216216
func BenchmarkRS512Signing(b *testing.B) {
217-
key, _ := ioutil.ReadFile("test/sample_key")
217+
key, _ := os.ReadFile("test/sample_key")
218218
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
219219
if err != nil {
220220
b.Fatal(err)

test/helpers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package test
33
import (
44
"crypto"
55
"crypto/rsa"
6-
"io/ioutil"
6+
"os"
77

88
"github.com/golang-jwt/jwt/v4"
99
)
1010

1111
func LoadRSAPrivateKeyFromDisk(location string) *rsa.PrivateKey {
12-
keyData, e := ioutil.ReadFile(location)
12+
keyData, e := os.ReadFile(location)
1313
if e != nil {
1414
panic(e.Error())
1515
}
@@ -21,7 +21,7 @@ func LoadRSAPrivateKeyFromDisk(location string) *rsa.PrivateKey {
2121
}
2222

2323
func LoadRSAPublicKeyFromDisk(location string) *rsa.PublicKey {
24-
keyData, e := ioutil.ReadFile(location)
24+
keyData, e := os.ReadFile(location)
2525
if e != nil {
2626
panic(e.Error())
2727
}
@@ -45,7 +45,7 @@ func MakeSampleToken(c jwt.Claims, method jwt.SigningMethod, key interface{}) st
4545
}
4646

4747
func LoadECPrivateKeyFromDisk(location string) crypto.PrivateKey {
48-
keyData, e := ioutil.ReadFile(location)
48+
keyData, e := os.ReadFile(location)
4949
if e != nil {
5050
panic(e.Error())
5151
}
@@ -57,7 +57,7 @@ func LoadECPrivateKeyFromDisk(location string) crypto.PrivateKey {
5757
}
5858

5959
func LoadECPublicKeyFromDisk(location string) crypto.PublicKey {
60-
keyData, e := ioutil.ReadFile(location)
60+
keyData, e := os.ReadFile(location)
6161
if e != nil {
6262
panic(e.Error())
6363
}

0 commit comments

Comments
 (0)