E591 cli: replace uses of deprecated io/ioutil · cloudflare/cfssl@45225c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45225c2

Browse files
committed
cli: replace uses of deprecated io/ioutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 6f34ba0 commit 45225c2

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

cli/cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"errors"
3131
"flag"
3232
"fmt"
33-
"io/ioutil"
33+
"io"
3434
"os"
3535

3636
"github.com/cloudflare/cfssl/config"
@@ -151,9 +151,9 @@ func Start(cmds map[string]*Command) error {
151151
// ReadStdin reads from stdin if the file is "-"
152152
func ReadStdin(filename string) ([]byte, error) {
153153
if filename == "-" {
154-
return ioutil.ReadAll(os.Stdin)
154+
return io.ReadAll(os.Stdin)
155155
}
156-
return ioutil.ReadFile(filename)
156+
return os.ReadFile(filename)
157157
}
158158

159159
// PrintCert outputs a cert, key and csr to stdout

cli/gencert/gencert_test.go

-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gencert
22

33
import (
4-
"io/ioutil"
54
"os"
65
"strings"
76
"testing"
@@ -86,8 +85,8 @@ func TestGencertFile(t *testing.T) {
8685
}
8786

8887
func TestGencertEnv(t *testing.T) {
89-
tempCaCert, _ := ioutil.ReadFile("../testdata/ca.pem")
90-
tempCaKey, _ := ioutil.ReadFile("../testdata/ca-key.pem")
88+
tempCaCert, _ := os.ReadFile("../testdata/ca.pem")
89+
tempCaKey, _ := os.ReadFile("../testdata/ca-key.pem")
9190
os.Setenv("ca", string(tempCaCert))
9291
os.Setenv("ca_key", string(tempCaKey))
9392

@@ -124,8 +123,8 @@ func TestGencertEnv(t *testing.T) {
124123
}
125124

126125
func TestBadGencertEnv(t *testing.T) {
127-
tempCaCert, _ := ioutil.ReadFile("../testdata/ca.pem")
128-
tempCaKey, _ := ioutil.ReadFile("../testdata/ca-key.pem")
126+
tempCaCert, _ := os.ReadFile("../testdata/ca.pem")
127+
tempCaKey, _ := os.ReadFile("../testdata/ca-key.pem")
129128
os.Setenv("ca", string(tempCaCert))
130129
os.Setenv("ca_key", string(tempCaKey))
131130

cli/gencsr/gencsr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package gencsr
33
import (
44
"encoding/json"
55
"errors"
6-
"io/ioutil"
6+
"io"
77
"os"
88
"testing"
99

@@ -36,7 +36,7 @@ func newStdoutRedirect() (*stdoutRedirect, error) {
3636
func (pipe *stdoutRedirect) readAll() ([]byte, error) {
3737
pipe.w.Close()
3838
os.Stdout = pipe.saved
39-
return ioutil.ReadAll(pipe.r)
39+
return io.ReadAll(pipe.r)
4040
}
4141

4242
func checkResponse(out []byte) error {

cli/genkey/genkey_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package genkey
33
import (
44
"encoding/json"
55
"errors"
6-
"io/ioutil"
6+
"io"
77
"os"
88
"testing"
99

@@ -30,7 +30,7 @@ func newStdoutRedirect() (*stdoutRedirect, error) {
3030
func (pipe *stdoutRedirect) readAll() ([]byte, error) {
3131
pipe.w.Close()
3232
os.Stdout = pipe.saved
33-
return ioutil.ReadAll(pipe.r)
33+
return io.ReadAll(pipe.r)
3434
}
3535

3636
func checkResponse(out []byte) error {

cli/ocsprefresh/ocsprefresh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ocsprefresh
22

33
import (
44
"encoding/hex"
5+
"os"
56
"testing"
67
"time"
78

@@ -11,15 +12,14 @@ import (
1112
"github.com/cloudflare/cfssl/cli"
1213
"github.com/cloudflare/cfssl/helpers"
1314
"golang.org/x/crypto/ocsp"
14-
"io/ioutil"
1515
)
1616

1717
var dbAccessor certdb.Accessor
1818

1919
func TestOCSPRefreshMain(t *testing.T) {
2020
db := testdb.SQLiteDB("../../certdb/testdb/certstore_development.db")
2121

22-
certPEM, err := ioutil.ReadFile("../../ocsp/testdata/cert.pem")
22+
certPEM, err := os.ReadFile("../../ocsp/testdata/cert.pem")
2323
if err != nil {
2424
t.Fatal(err)
2525
}

cli/ocspsign/ocspsign.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package ocspsign
33

44
import (
5-
"io/ioutil"
5+
"os"
66
"time"
77

88
"github.com/cloudflare/cfssl/cli"
@@ -27,7 +27,7 @@ var ocspSignerFlags = []string{"ca", "responder", "responder-key", "reason", "st
2727
// ocspSignerMain is the main CLI of OCSP signer functionality.
2828
func ocspSignerMain(args []string, c cli.Config) (err error) {
2929
// Read the cert to be revoked from file
30-
certBytes, err := ioutil.ReadFile(c.CertFile)
30+
certBytes, err := os.ReadFile(c.CertFile)
3131
if err != nil {
3232
log.Critical("Unable to read certificate: ", err)
3333
return
@@ -80,8 +80,8 @@ func ocspSignerMain(args []string, c cli.Config) (err error) {
8080

8181
// SignerFromConfig creates a signer from a cli.Config as a helper for cli and serve
8282
func SignerFromConfig(c cli.Config) (ocsp.Signer, error) {
83-
//if this is called from serve then we need to use the specific responder key file
84-
//fallback to key for backwards-compatibility
83+
// if this is called from serve then we need to use the specific responder key file
84+
// fallback to key for backwards-compatibility
8585
k := c.ResponderKeyFile
8686
if k == "" {
8787
k = c.KeyFile

cli/sign/sign.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package sign
44
import (
55
"encoding/json"
66
"errors"
7-
"io/ioutil"
7+
"os"
88

99
"github.com/cloudflare/cfssl/certdb/dbconf"
1010
certsql "github.com/cloudflare/cfssl/certdb/sql"
@@ -127,7 +127,7 @@ func signerMain(args []string, c cli.Config) (err error) {
127127
}
128128

129129
var subjectJSON []byte
130-
subjectJSON, err = ioutil.ReadFile(subjectFile)
130+
subjectJSON, err = os.ReadFile(subjectFile)
131131
if err != nil {
132132
return
133133
}

0 commit comments

Comments
 (0)
0