Skip to content

Commit

Permalink
transport: 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 6a932bb commit 8bd4af2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions transport/example/maclient/client.go
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/cloudflare/cfssl/transport"
"github.com/cloudflare/cfssl/transport/core"
Expand All @@ -25,7 +25,7 @@ func main() {
flag.Parse()

var id = new(core.Identity)
data, err := ioutil.ReadFile(conf)
data, err := os.ReadFile(conf)
if err != nil {
exlib.Err(1, err, "reading config file")
}
Expand Down
4 changes: 2 additions & 2 deletions transport/example/maserver/server.go
Expand Up @@ -3,8 +3,8 @@ package main
import (
"encoding/json"
"flag"
"io/ioutil"
"net"
"os"

"github.com/cloudflare/cfssl/log"
"github.com/cloudflare/cfssl/transport"
Expand All @@ -23,7 +23,7 @@ func main() {
flag.Parse()

var id = new(core.Identity)
data, err := ioutil.ReadFile(conf)
data, err := os.ReadFile(conf)
if err != nil {
exlib.Err(1, err, "reading config file")
}
Expand Down
10 changes: 5 additions & 5 deletions transport/kp/key_provider.go
Expand Up @@ -22,7 +22,7 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"io/ioutil"
"os"
"strings"

"github.com/cloudflare/cfssl/csr"
Expand Down Expand Up @@ -288,7 +288,7 @@ func (sp *StandardProvider) Load() (err error) {
}
}()

sp.internal.keyPEM, err = ioutil.ReadFile(sp.Paths.KeyFile)
sp.internal.keyPEM, err = os.ReadFile(sp.Paths.KeyFile)
if err != nil {
return
}
Expand All @@ -300,7 +300,7 @@ func (sp *StandardProvider) Load() (err error) {

clearKey = false

sp.internal.certPEM, err = ioutil.ReadFile(sp.Paths.CertFile)
sp.internal.certPEM, err = os.ReadFile(sp.Paths.CertFile)
if err != nil {
return ErrCertificateUnavailable
}
Expand Down Expand Up @@ -384,12 +384,12 @@ func (sp *StandardProvider) Store() error {
return errors.New("transport: provider does not have a key and certificate")
}

err := ioutil.WriteFile(sp.Paths.CertFile, sp.internal.certPEM, 0644)
err := os.WriteFile(sp.Paths.CertFile, sp.internal.certPEM, 0644)
if err != nil {
return err
}

return ioutil.WriteFile(sp.Paths.KeyFile, sp.internal.keyPEM, 0600)
return os.WriteFile(sp.Paths.KeyFile, sp.internal.keyPEM, 0600)
}

// X509KeyPair returns a tls.Certificate for the provider.
Expand Down
4 changes: 2 additions & 2 deletions transport/roots/provider.go
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/sha256"
"crypto/x509"
"errors"
"io/ioutil"
"os"

"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/transport/core"
Expand Down Expand Up @@ -114,7 +114,7 @@ func TrustPEM(metadata map[string]string) ([]*x509.Certificate, error) {
return nil, errors.New("transport: PEM source requires a source file")
}

in, err := ioutil.ReadFile(sourceFile)
in, err := os.ReadFile(sourceFile)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions transport/roots/system/root_plan9.go
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build plan9
// +build plan9

package system

import (
"crypto/x509"
"io/ioutil"
)

// Possible certificate files; stop after finding one.
Expand All @@ -18,7 +18,7 @@ var certFiles = []string{

func initSystemRoots() (roots []*x509.Certificate) {
for _, file := range certFiles {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err == nil {
roots, _ = appendPEM(roots, data)
return
Expand Down
9 changes: 5 additions & 4 deletions transport/roots/system/root_unix.go
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
// +build dragonfly freebsd linux nacl netbsd openbsd solaris

package system

import (
"crypto/x509"
"io/ioutil"
"os"
)

// Possible directories with certificate files; stop after successfully
Expand All @@ -20,22 +21,22 @@ var certDirectories = []string{
func initSystemRoots() []*x509.Certificate {
var roots []*x509.Certificate
for _, file := range certFiles {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err == nil {
roots, _ = appendPEM(roots, data)
return roots
}
}

for _, directory := range certDirectories {
fis, err := ioutil.ReadDir(directory)
fis, err := os.ReadDir(directory)
if err != nil {
continue
}
rootsAdded := false
for _, fi := range fis {
var ok bool
data, err := ioutil.ReadFile(directory + "/" + fi.Name())
data, err := os.ReadFile(directory + "/" + fi.Name())
if err == nil {
if roots, ok = appendPEM(roots, data); ok {
rootsAdded = true
Expand Down

0 comments on commit 8bd4af2

Please sign in to comment.