Skip to content

Commit

Permalink
cli: 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 6f34ba0 commit 45225c2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/cloudflare/cfssl/config"
Expand Down Expand Up @@ -151,9 +151,9 @@ func Start(cmds map[string]*Command) error {
// ReadStdin reads from stdin if the file is "-"
func ReadStdin(filename string) ([]byte, error) {
if filename == "-" {
return ioutil.ReadAll(os.Stdin)
return io.ReadAll(os.Stdin)
}
return ioutil.ReadFile(filename)
return os.ReadFile(filename)
}

// PrintCert outputs a cert, key and csr to stdout
Expand Down
9 changes: 4 additions & 5 deletions cli/gencert/gencert_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gencert

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -86,8 +85,8 @@ func TestGencertFile(t *testing.T) {
}

func TestGencertEnv(t *testing.T) {
tempCaCert, _ := ioutil.ReadFile("../testdata/ca.pem")
tempCaKey, _ := ioutil.ReadFile("../testdata/ca-key.pem")
tempCaCert, _ := os.ReadFile("../testdata/ca.pem")
tempCaKey, _ := os.ReadFile("../testdata/ca-key.pem")
os.Setenv("ca", string(tempCaCert))
os.Setenv("ca_key", string(tempCaKey))

Expand Down Expand Up @@ -124,8 +123,8 @@ func TestGencertEnv(t *testing.T) {
}

func TestBadGencertEnv(t *testing.T) {
tempCaCert, _ := ioutil.ReadFile("../testdata/ca.pem")
tempCaKey, _ := ioutil.ReadFile("../testdata/ca-key.pem")
tempCaCert, _ := os.ReadFile("../testdata/ca.pem")
tempCaKey, _ := os.ReadFile("../testdata/ca-key.pem")
os.Setenv("ca", string(tempCaCert))
os.Setenv("ca_key", string(tempCaKey))

Expand Down
4 changes: 2 additions & 2 deletions cli/gencsr/gencsr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gencsr
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -36,7 +36,7 @@ func newStdoutRedirect() (*stdoutRedirect, error) {
func (pipe *stdoutRedirect) readAll() ([]byte, error) {
pipe.w.Close()
os.Stdout = pipe.saved
return ioutil.ReadAll(pipe.r)
return io.ReadAll(pipe.r)
}

func checkResponse(out []byte) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/genkey/genkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package genkey
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"os"
"testing"

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

func checkResponse(out []byte) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/ocsprefresh/ocsprefresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocsprefresh

import (
"encoding/hex"
"os"
"testing"
"time"

Expand All @@ -11,15 +12,14 @@ import (
"github.com/cloudflare/cfssl/cli"
"github.com/cloudflare/cfssl/helpers"
"golang.org/x/crypto/ocsp"
"io/ioutil"
)

var dbAccessor certdb.Accessor

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

certPEM, err := ioutil.ReadFile("../../ocsp/testdata/cert.pem")
certPEM, err := os.ReadFile("../../ocsp/testdata/cert.pem")
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cli/ocspsign/ocspsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package ocspsign

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

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

// SignerFromConfig creates a signer from a cli.Config as a helper for cli and serve
func SignerFromConfig(c cli.Config) (ocsp.Signer, error) {
//if this is called from serve then we need to use the specific responder key file
//fallback to key for backwards-compatibility
// if this is called from serve then we need to use the specific responder key file
// fallback to key for backwards-compatibility
k := c.ResponderKeyFile
if k == "" {
k = c.KeyFile
Expand Down
4 changes: 2 additions & 2 deletions cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package sign
import (
"encoding/json"
"errors"
"io/ioutil"
"os"

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

var subjectJSON []byte
subjectJSON, err = ioutil.ReadFile(subjectFile)
subjectJSON, err = os.ReadFile(subjectFile)
if err != nil {
return
}
Expand Down

0 comments on commit 45225c2

Please sign in to comment.