Skip to content

Commit 6572a53

Browse files
authored
Update ioutil.ReadFile to os.ReadFile (#230)
1 parent a0adba5 commit 6572a53

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

certificate/certificate.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"crypto/x509"
99
"encoding/pem"
1010
"errors"
11-
"io/ioutil"
11+
"os"
1212
"strings"
1313

1414
"golang.org/x/crypto/pkcs12"
@@ -29,7 +29,7 @@ var (
2929
// Use "" as the password argument if the PKCS#12 certificate is not password
3030
// protected.
3131
func FromP12File(filename string, password string) (tls.Certificate, error) {
32-
p12bytes, err := ioutil.ReadFile(filename)
32+
p12bytes, err := os.ReadFile(filename)
3333
if err != nil {
3434
return tls.Certificate{}, err
3535
}
@@ -62,7 +62,7 @@ func FromP12Bytes(bytes []byte, password string) (tls.Certificate, error) {
6262
// Use "" as the password argument if the PEM certificate is not password
6363
// protected.
6464
func FromPemFile(filename string, password string) (tls.Certificate, error) {
65-
bytes, err := ioutil.ReadFile(filename)
65+
bytes, err := os.ReadFile(filename)
6666
if err != nil {
6767
return tls.Certificate{}, err
6868
}

certificate/certificate_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package certificate_test
33
import (
44
"crypto/tls"
55
"errors"
6-
"io/ioutil"
6+
"os"
77
"testing"
88

99
"github.com/sideshow/apns2/certificate"
@@ -19,7 +19,7 @@ func TestValidCertificateFromP12File(t *testing.T) {
1919
}
2020

2121
func TestValidCertificateFromP12Bytes(t *testing.T) {
22-
bytes, _ := ioutil.ReadFile("_fixtures/certificate-valid.p12")
22+
bytes, _ := os.ReadFile("_fixtures/certificate-valid.p12")
2323
cer, err := certificate.FromP12Bytes(bytes, "")
2424
assert.NoError(t, err)
2525
assert.NotEqual(t, tls.Certificate{}, cer)
@@ -52,7 +52,7 @@ func TestValidCertificateFromPemFile(t *testing.T) {
5252
}
5353

5454
func TestValidCertificateFromPemBytes(t *testing.T) {
55-
bytes, _ := ioutil.ReadFile("_fixtures/certificate-valid.pem")
55+
bytes, _ := os.ReadFile("_fixtures/certificate-valid.pem")
5656
cer, err := certificate.FromPemBytes(bytes, "")
5757
assert.NoError(t, err)
5858
assert.NotEqual(t, tls.Certificate{}, cer)
@@ -65,7 +65,7 @@ func TestValidCertificateFromPemFileWithPKCS8PrivateKey(t *testing.T) {
6565
}
6666

6767
func TestValidCertificateFromPemBytesWithPKCS8PrivateKey(t *testing.T) {
68-
bytes, _ := ioutil.ReadFile("_fixtures/certificate-valid-pkcs8.pem")
68+
bytes, _ := os.ReadFile("_fixtures/certificate-valid-pkcs8.pem")
6969
cer, err := certificate.FromPemBytes(bytes, "")
7070
assert.NoError(t, err)
7171
assert.NotEqual(t, tls.Certificate{}, cer)

token/token.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"crypto/x509"
66
"encoding/pem"
77
"errors"
8-
"io/ioutil"
8+
"os"
99
"sync"
1010
"time"
1111

@@ -40,7 +40,7 @@ type Token struct {
4040
// AuthKeyFromFile loads a .p8 certificate from a local file and returns a
4141
// *ecdsa.PrivateKey.
4242
func AuthKeyFromFile(filename string) (*ecdsa.PrivateKey, error) {
43-
bytes, err := ioutil.ReadFile(filename)
43+
bytes, err := os.ReadFile(filename)
4444
if err != nil {
4545
return nil, err
4646
}

token/token_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"crypto/elliptic"
66
"crypto/rand"
77
"errors"
8-
"io/ioutil"
8+
"os"
99
"testing"
1010
"time"
1111

@@ -21,7 +21,7 @@ func TestValidTokenFromP8File(t *testing.T) {
2121
}
2222

2323
func TestValidTokenFromP8Bytes(t *testing.T) {
24-
bytes, _ := ioutil.ReadFile("_fixtures/authkey-valid.p8")
24+
bytes, _ := os.ReadFile("_fixtures/authkey-valid.p8")
2525
_, err := token.AuthKeyFromBytes(bytes)
2626
assert.NoError(t, err)
2727
}

0 commit comments

Comments
 (0)