Skip to content

Commit

Permalink
ocsp: replace uses of deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Nov 20, 2022
1 parent e7d48f1 commit 5b8919c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
8 changes: 3 additions & 5 deletions ocsp/ocsp.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*
Package ocsp exposes OCSP signing functionality, much like the signer
package does for certificate signing. It also provies a basic OCSP
responder stack for serving pre-signed OCSP responses.
*/
package ocsp

Expand All @@ -12,7 +10,7 @@ import (
"crypto"
"crypto/x509"
"crypto/x509/pkix"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -113,12 +111,12 @@ func NewSignerFromFile(issuerFile, responderFile, keyFile string, interval time.
return nil, err
}
log.Debug("Loading responder cert: ", responderFile)
responderBytes, err := ioutil.ReadFile(responderFile)
responderBytes, err := os.ReadFile(responderFile)
if err != nil {
return nil, err
}
log.Debug("Loading responder key: ", keyFile)
keyBytes, err := ioutil.ReadFile(keyFile)
keyBytes, err := os.ReadFile(keyFile)
if err != nil {
return nil, cferr.Wrap(cferr.CertificateError, cferr.ReadFailed, err)
}
Expand Down
8 changes: 4 additions & 4 deletions ocsp/ocsp_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ocsp

import (
"io/ioutil"
"os"
"testing"
"time"

"golang.org/x/crypto/ocsp"

"github.com/cloudflare/cfssl/helpers"

"golang.org/x/crypto/ocsp"
)

const (
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestNewSignerFromFile(t *testing.T) {

func setup(t *testing.T) (SignRequest, time.Duration) {
dur, _ := time.ParseDuration("1ms")
certPEM, err := ioutil.ReadFile(otherCertFile)
certPEM, err := os.ReadFile(otherCertFile)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions ocsp/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
"regexp"
"time"

Expand Down Expand Up @@ -131,7 +132,7 @@ func (src DBSource) Response(req *ocsp.Request) ([]byte, http.Header, error) {
// PEM without headers or whitespace). Invalid responses are ignored.
// This function pulls the entire file into an InMemorySource.
func NewSourceFromFile(responseFile string) (Source, error) {
fileContents, err := ioutil.ReadFile(responseFile)
fileContents, err := os.ReadFile(responseFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -309,7 +310,7 @@ func (rs Responder) ServeHTTP(response http.ResponseWriter, request *http.Reques
return
}
case "POST":
requestBody, err = ioutil.ReadAll(request.Body)
requestBody, err = io.ReadAll(request.Body)
if err != nil {
log.Errorf("Problem reading body of POST: %s", err)
response.WriteHeader(http.StatusBadRequest)
Expand Down
12 changes: 6 additions & 6 deletions ocsp/responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package ocsp

import (
"encoding/hex"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -210,11 +210,11 @@ func TestSqliteTrivial(t *testing.T) {
// an OCSP request.
certFile := "testdata/sqlite_ca.pem"
issuerFile := "testdata/ca.pem"
certContent, err := ioutil.ReadFile(certFile)
certContent, err := os.ReadFile(certFile)
if err != nil {
t.Errorf("Error reading cert file: %s", err)
}
issuerContent, err := ioutil.ReadFile(issuerFile)
issuerContent, err := os.ReadFile(issuerFile)
if err != nil {
t.Errorf("Error reading issuer file: %s", err)
}
Expand Down Expand Up @@ -274,11 +274,11 @@ func TestSqliteRealResponse(t *testing.T) {

certFile := "testdata/cert.pem"
issuerFile := "testdata/ca.pem"
certContent, err := ioutil.ReadFile(certFile)
certContent, err := os.ReadFile(certFile)
if err != nil {
t.Errorf("Error reading cert file: %s", err)
}
issuerContent, err := ioutil.ReadFile(issuerFile)
issuerContent, err := os.ReadFile(issuerFile)
if err != nil {
t.Errorf("Error reading issuer file: %s", err)
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestSqliteRealResponse(t *testing.T) {
ThisUpdate: time.Now(),
NextUpdate: time.Now().AddDate(0, 1, 0),
}
keyPEM, err := ioutil.ReadFile("testdata/ca-key.pem")
keyPEM, err := os.ReadFile("testdata/ca-key.pem")
if err != nil {
t.Errorf("Error reading private key file: %s", err)
}
Expand Down

0 comments on commit 5b8919c

Please sign in to comment.