Skip to content

Commit

Permalink
Update ioutil.ReadFile to os.ReadFile (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshow authored Aug 11, 2024
1 parent a0adba5 commit 6572a53
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"io/ioutil"
"os"
"strings"

"golang.org/x/crypto/pkcs12"
Expand All @@ -29,7 +29,7 @@ var (
// Use "" as the password argument if the PKCS#12 certificate is not password
// protected.
func FromP12File(filename string, password string) (tls.Certificate, error) {
p12bytes, err := ioutil.ReadFile(filename)
p12bytes, err := os.ReadFile(filename)
if err != nil {
return tls.Certificate{}, err
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func FromP12Bytes(bytes []byte, password string) (tls.Certificate, error) {
// Use "" as the password argument if the PEM certificate is not password
// protected.
func FromPemFile(filename string, password string) (tls.Certificate, error) {
bytes, err := ioutil.ReadFile(filename)
bytes, err := os.ReadFile(filename)
if err != nil {
return tls.Certificate{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions certificate/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package certificate_test
import (
"crypto/tls"
"errors"
"io/ioutil"
"os"
"testing"

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

func TestValidCertificateFromP12Bytes(t *testing.T) {
bytes, _ := ioutil.ReadFile("_fixtures/certificate-valid.p12")
bytes, _ := os.ReadFile("_fixtures/certificate-valid.p12")
cer, err := certificate.FromP12Bytes(bytes, "")
assert.NoError(t, err)
assert.NotEqual(t, tls.Certificate{}, cer)
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestValidCertificateFromPemFile(t *testing.T) {
}

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

func TestValidCertificateFromPemBytesWithPKCS8PrivateKey(t *testing.T) {
bytes, _ := ioutil.ReadFile("_fixtures/certificate-valid-pkcs8.pem")
bytes, _ := os.ReadFile("_fixtures/certificate-valid-pkcs8.pem")
cer, err := certificate.FromPemBytes(bytes, "")
assert.NoError(t, err)
assert.NotEqual(t, tls.Certificate{}, cer)
Expand Down
4 changes: 2 additions & 2 deletions token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"io/ioutil"
"os"
"sync"
"time"

Expand Down Expand Up @@ -40,7 +40,7 @@ type Token struct {
// AuthKeyFromFile loads a .p8 certificate from a local file and returns a
// *ecdsa.PrivateKey.
func AuthKeyFromFile(filename string) (*ecdsa.PrivateKey, error) {
bytes, err := ioutil.ReadFile(filename)
bytes, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/elliptic"
"crypto/rand"
"errors"
"io/ioutil"
"os"
"testing"
"time"

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

func TestValidTokenFromP8Bytes(t *testing.T) {
bytes, _ := ioutil.ReadFile("_fixtures/authkey-valid.p8")
bytes, _ := os.ReadFile("_fixtures/authkey-valid.p8")
_, err := token.AuthKeyFromBytes(bytes)
assert.NoError(t, err)
}
Expand Down

0 comments on commit 6572a53

Please sign in to comment.