Skip to content

Commit c71f9f6

Browse files
authored
Merge pull request #1258 from thaJeztah/remove_ioutils
chore: remove uses of deprecated io/ioutil
2 parents b553d93 + 68b96f8 commit c71f9f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+294
-301
lines changed

api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33

44
import (
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88

99
"github.com/cloudflare/cfssl/errors"
@@ -92,7 +92,7 @@ func (h HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
9292
func readRequestBlob(r *http.Request) (map[string]string, error) {
9393
var blob map[string]string
9494

95-
body, err := ioutil.ReadAll(r.Body)
95+
body, err := io.ReadAll(r.Body)
9696
if err != nil {
9797
return nil, err
9898
}

api/api_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -52,7 +52,7 @@ func post(t *testing.T, obj map[string]interface{}, ts *httptest.Server) (resp *
5252
if err != nil {
5353
t.Fatal(err)
5454
}
55-
body, err = ioutil.ReadAll(resp.Body)
55+
body, err = io.ReadAll(resp.Body)
5656
if err != nil {
5757
t.Fatal(err)
5858
}
@@ -65,7 +65,7 @@ func get(t *testing.T, ts *httptest.Server) (resp *http.Response, body []byte) {
6565
t.Fatal(err)
6666
}
6767

68-
body, err = ioutil.ReadAll(resp.Body)
68+
body, err = io.ReadAll(resp.Body)
6969
if err != nil {
7070
t.Fatal(err)
7171
}

api/bundle/bundle_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package bundle
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
9+
"os"
910
"testing"
1011

1112
"github.com/cloudflare/cfssl/api"
@@ -39,14 +40,14 @@ func testBundleFile(t *testing.T, domain, ip, certFile, keyFile, flavor string)
3940
var certPEM, keyPEM []byte
4041
if certFile != "" {
4142
var err error
42-
certPEM, err = ioutil.ReadFile(certFile)
43+
certPEM, err = os.ReadFile(certFile)
4344
if err != nil {
4445
t.Fatal(err)
4546
}
4647
}
4748
if keyFile != "" {
4849
var err error
49-
keyPEM, err = ioutil.ReadFile(keyFile)
50+
keyPEM, err = os.ReadFile(keyFile)
5051
if err != nil {
5152
t.Fatal(err)
5253
}
@@ -75,7 +76,7 @@ func testBundleFile(t *testing.T, domain, ip, certFile, keyFile, flavor string)
7576
if err != nil {
7677
t.Fatal(err)
7778
}
78-
body, err = ioutil.ReadAll(resp.Body)
79+
body, err = io.ReadAll(resp.Body)
7980
if err != nil {
8081
t.Fatal(err)
8182
}

api/certadd/insert.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package certadd
33
import (
44
"bytes"
55
"database/sql"
6+
"encoding/base64"
67
"encoding/hex"
78
"encoding/json"
8-
"io/ioutil"
9+
"io"
910
"math/big"
1011
"net/http"
1112
"time"
@@ -17,8 +18,6 @@ import (
1718
"github.com/cloudflare/cfssl/ocsp"
1819
"github.com/jmoiron/sqlx/types"
1920

20-
"encoding/base64"
21-
2221
stdocsp "golang.org/x/crypto/ocsp"
2322
)
2423

@@ -81,7 +80,7 @@ var validReasons = map[int]bool{
8180

8281
// Handle handles HTTP requests to add certificates
8382
func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
84-
body, err := ioutil.ReadAll(r.Body)
83+
body, err := io.ReadAll(r.Body)
8584
if err != nil {
8685
return err
8786
}

api/certadd/insert_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"crypto/rsa"
77
"crypto/x509"
88
"crypto/x509/pkix"
9+
"encoding/base64"
910
"encoding/hex"
1011
"encoding/json"
1112
"encoding/pem"
12-
"io/ioutil"
13+
"io"
1314
"math/big"
1415
"net/http"
1516
"net/http/httptest"
@@ -21,8 +22,6 @@ import (
2122
"github.com/cloudflare/cfssl/certdb/testdb"
2223
"github.com/cloudflare/cfssl/ocsp"
2324

24-
"encoding/base64"
25-
2625
stdocsp "golang.org/x/crypto/ocsp"
2726
)
2827

@@ -47,7 +46,7 @@ func makeRequest(t *testing.T, dbAccessor certdb.Accessor, signer ocsp.Signer, r
4746
t.Fatal(err)
4847
}
4948

50-
body, err = ioutil.ReadAll(resp.Body)
49+
body, err = io.ReadAll(resp.Body)
5150
if err != nil {
5251
t.Fatal(err)
5352
}

api/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"encoding/json"
88
stderr "errors"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net"
1212
"net/http"
1313
"net/url"
@@ -158,7 +158,7 @@ func (srv *server) post(url string, jsonData []byte) (*api.Response, error) {
158158
}
159159
defer req.Body.Close()
160160
defer resp.Body.Close()
161-
body, err := ioutil.ReadAll(resp.Body)
161+
body, err := io.ReadAll(resp.Body)
162162
if err != nil {
163163
return nil, errors.Wrap(errors.APIClientError, errors.IOError, err)
164164
}

api/crl/crl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"crypto/x509"
55
"encoding/base64"
66
"encoding/json"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/httptest"
1010
"testing"
@@ -61,7 +61,7 @@ func testGetCRL(t *testing.T, dbAccessor certdb.Accessor, expiry string) (resp *
6161
if err != nil {
6262
t.Fatal(err)
6363
}
64-
body, err = ioutil.ReadAll(resp.Body)
64+
body, err = io.ReadAll(resp.Body)
6565
if err != nil {
6666
t.Fatal(err)
6767
}

api/gencrl/gencrl.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import (
55
"crypto/rand"
66
"crypto/x509/pkix"
77
"encoding/json"
8-
"github.com/cloudflare/cfssl/api"
9-
"github.com/cloudflare/cfssl/errors"
10-
"github.com/cloudflare/cfssl/helpers"
11-
"github.com/cloudflare/cfssl/log"
12-
"io/ioutil"
8+
"io"
139
"math/big"
1410
"net/http"
1511
"strconv"
1612
"strings"
1713
"time"
14+
15+
"github.com/cloudflare/cfssl/api"
16+
"github.com/cloudflare/cfssl/errors"
17+
"github.com/cloudflare/cfssl/helpers"
18+
"github.com/cloudflare/cfssl/log"
1819
)
1920

2021
// This type is meant to be unmarshalled from JSON
@@ -32,7 +33,7 @@ func gencrlHandler(w http.ResponseWriter, r *http.Request) error {
3233
var oneWeek = time.Duration(604800) * time.Second
3334
var newExpiryTime = time.Now()
3435

35-
body, err := ioutil.ReadAll(r.Body)
36+
body, err := io.ReadAll(r.Body)
3637
if err != nil {
3738
return err
3839
}

api/gencrl/gencrl_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package gencrl
33
import (
44
"bytes"
55
"encoding/json"
6-
"github.com/cloudflare/cfssl/api"
7-
"io/ioutil"
6+
"io"
87
"net/http"
98
"net/http/httptest"
9+
"os"
1010
"testing"
11+
12+
"github.com/cloudflare/cfssl/api"
1113
)
1214

1315
const (
@@ -55,7 +57,7 @@ func testCRLCreation(t *testing.T, issuingKey, certFile string, expiry string, s
5557
obj := map[string]interface{}{}
5658

5759
if certFile != "" {
58-
c, err := ioutil.ReadFile(certFile)
60+
c, err := os.ReadFile(certFile)
5961
if err != nil {
6062
t.Fatal(err)
6163
}
@@ -65,7 +67,7 @@ func testCRLCreation(t *testing.T, issuingKey, certFile string, expiry string, s
6567
obj["serialNumber"] = serialList
6668

6769
if issuingKey != "" {
68-
c, err := ioutil.ReadFile(issuingKey)
70+
c, err := os.ReadFile(issuingKey)
6971
if err != nil {
7072
t.Fatal(err)
7173
}
@@ -83,7 +85,7 @@ func testCRLCreation(t *testing.T, issuingKey, certFile string, expiry string, s
8385
if err != nil {
8486
t.Fatal(err)
8587
}
86-
body, err = ioutil.ReadAll(resp.Body)
88+
body, err = io.ReadAll(resp.Body)
8789
if err != nil {
8890
t.Fatal(err)
8991
}
@@ -103,5 +105,4 @@ func TestCRL(t *testing.T) {
103105
t.Logf("failed to read response body: %v", err)
104106
t.Fatal(resp.Status, tester.ExpectedHTTPStatus, message)
105107
}
106-
107108
}

api/generator/generator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"encoding/json"
99
"encoding/pem"
1010
"fmt"
11-
"io/ioutil"
11+
"io"
1212
"net/http"
1313

1414
"github.com/cloudflare/cfssl/api"
@@ -107,7 +107,7 @@ func computeSum(in []byte) (sum Sum, err error) {
107107
// these requests is documented in the API documentation.
108108
func (g *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
109109
log.Info("request for CSR")
110-
body, err := ioutil.ReadAll(r.Body)
110+
body, err := io.ReadAll(r.Body)
111111
if err != nil {
112112
log.Warningf("failed to read request body: %v", err)
113113
return errors.NewBadRequest(err)
@@ -228,7 +228,7 @@ func (cg *CertGeneratorHandler) Handle(w http.ResponseWriter, r *http.Request) e
228228
req := new(genSignRequest)
229229
req.Request = csr.New()
230230

231-
body, err := ioutil.ReadAll(r.Body)
231+
body, err := io.ReadAll(r.Body)
232232
if err != nil {
233233
log.Warningf("failed to read request body: %v", err)
234234
return errors.NewBadRequest(err)

api/info/info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package info
33

44
import (
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88

99
"github.com/cloudflare/cfssl/api"
@@ -34,7 +34,7 @@ func NewHandler(s signer.Signer) (http.Handler, error) {
3434
// a list containing information on each root certificate.
3535
func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
3636
req := new(info.Req)
37-
body, err := ioutil.ReadAll(r.Body)
37+
body, err := io.ReadAll(r.Body)
3838
if err != nil {
3939
log.Warningf("failed to read request body: %v", err)
4040
return errors.NewBadRequest(err)
@@ -84,7 +84,7 @@ func NewMultiHandler(signers map[string]signer.Signer, defaultLabel string) (htt
8484
// the label is empty, the default label is used.
8585
func (h *MultiHandler) Handle(w http.ResponseWriter, r *http.Request) error {
8686
req := new(info.Req)
87-
body, err := ioutil.ReadAll(r.Body)
87+
body, err := io.ReadAll(r.Body)
8888
if err != nil {
8989
log.Warningf("failed to read request body: %v", err)
9090
return errors.NewBadRequest(err)

api/info/info_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package info
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -92,7 +92,7 @@ func testInfoFile(t *testing.T, req map[string]interface{}) (resp *http.Response
9292
if err != nil {
9393
t.Fatal(err)
9494
}
95-
body, err = ioutil.ReadAll(resp.Body)
95+
body, err = io.ReadAll(resp.Body)
9696
if err != nil {
9797
t.Fatal(err)
9898
}
@@ -112,7 +112,7 @@ func testMultiInfoFile(t *testing.T, req map[string]interface{}) (resp *http.Res
112112
if err != nil {
113113
t.Fatal(err)
114114
}
115-
body, err = ioutil.ReadAll(resp.Body)
115+
body, err = io.ReadAll(resp.Body)
116116
if err != nil {
117117
t.Fatal(err)
118118
}

api/initca/initca.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package initca
33

44
import (
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88

99
"github.com/cloudflare/cfssl/api"
@@ -26,7 +26,7 @@ type NewCA struct {
2626
// suitable for creating intermediate certificates.
2727
func initialCAHandler(w http.ResponseWriter, r *http.Request) error {
2828
log.Info("setting up initial CA handler")
29-
body, err := ioutil.ReadAll(r.Body)
29+
body, err := io.ReadAll(r.Body)
3030
if err != nil {
3131
log.Warningf("failed to read request body: %v", err)
3232
return errors.NewBadRequest(err)

api/ocsp/ocspsign.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package ocsp
33

44
import (
55
"crypto"
6-
"net/http"
7-
86
"encoding/base64"
97
"encoding/json"
10-
"io/ioutil"
8+
"io"
9+
"net/http"
1110
"time"
1211

1312
"github.com/cloudflare/cfssl/api"
@@ -56,7 +55,7 @@ var nameToHash = map[string]crypto.Hash{
5655
// is revoked then it also adds reason and revoked_at. The response is
5756
// base64 encoded.
5857
func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
59-
body, err := ioutil.ReadAll(r.Body)
58+
body, err := io.ReadAll(r.Body)
6059
if err != nil {
6160
return err
6261
}

0 commit comments

Comments
 (0)