From ab17d606f950872d4521eae8f368eaed7d80cb79 Mon Sep 17 00:00:00 2001 From: sideshow Date: Thu, 8 Aug 2024 21:15:46 +1200 Subject: [PATCH] Update ioutil.ReadFile to os.ReadFile --- certificate/certificate.go | 6 +++--- certificate/certificate_test.go | 8 ++++---- token/token.go | 4 ++-- token/token_test.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/certificate/certificate.go b/certificate/certificate.go index 6496720a..7ed6590d 100644 --- a/certificate/certificate.go +++ b/certificate/certificate.go @@ -8,7 +8,7 @@ import ( "crypto/x509" "encoding/pem" "errors" - "io/ioutil" + "os" "strings" "golang.org/x/crypto/pkcs12" @@ -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 } @@ -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 } diff --git a/certificate/certificate_test.go b/certificate/certificate_test.go index b04eeac1..c52b3073 100644 --- a/certificate/certificate_test.go +++ b/certificate/certificate_test.go @@ -3,7 +3,7 @@ package certificate_test import ( "crypto/tls" "errors" - "io/ioutil" + "os" "testing" "github.com/sideshow/apns2/certificate" @@ -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) @@ -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) @@ -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) diff --git a/token/token.go b/token/token.go index 26fec563..bf26e1a9 100644 --- a/token/token.go +++ b/token/token.go @@ -5,7 +5,7 @@ import ( "crypto/x509" "encoding/pem" "errors" - "io/ioutil" + "os" "sync" "time" @@ -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 } diff --git a/token/token_test.go b/token/token_test.go index ef3c6fd1..87a45aab 100644 --- a/token/token_test.go +++ b/token/token_test.go @@ -5,7 +5,7 @@ import ( "crypto/elliptic" "crypto/rand" "errors" - "io/ioutil" + "os" "testing" "time" @@ -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) }