Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #987

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cmd/nebula-cert/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math"
"net"
"os"
Expand Down Expand Up @@ -219,9 +218,9 @@ func ca(args []string, out io.Writer, errOut io.Writer, pr PasswordReader) error
return fmt.Errorf("error while encrypting out-key: %s", err)
}

err = ioutil.WriteFile(*cf.outKeyPath, b, 0600)
err = os.WriteFile(*cf.outKeyPath, b, 0600)
} else {
err = ioutil.WriteFile(*cf.outKeyPath, cert.MarshalSigningPrivateKey(curve, rawPriv), 0600)
err = os.WriteFile(*cf.outKeyPath, cert.MarshalSigningPrivateKey(curve, rawPriv), 0600)
}

if err != nil {
Expand All @@ -233,7 +232,7 @@ func ca(args []string, out io.Writer, errOut io.Writer, pr PasswordReader) error
return fmt.Errorf("error while marshalling certificate: %s", err)
}

err = ioutil.WriteFile(*cf.outCertPath, b, 0600)
err = os.WriteFile(*cf.outCertPath, b, 0600)
if err != nil {
return fmt.Errorf("error while writing out-crt: %s", err)
}
Expand All @@ -244,7 +243,7 @@ func ca(args []string, out io.Writer, errOut io.Writer, pr PasswordReader) error
return fmt.Errorf("error while generating qr code: %s", err)
}

err = ioutil.WriteFile(*cf.outQRPath, b, 0600)
err = os.WriteFile(*cf.outQRPath, b, 0600)
if err != nil {
return fmt.Errorf("error while writing out-qr: %s", err)
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/nebula-cert/ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"encoding/pem"
"errors"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -107,7 +106,7 @@ func Test_ca(t *testing.T) {
assert.Equal(t, "", eb.String())

// create temp key file
keyF, err := ioutil.TempFile("", "test.key")
keyF, err := os.CreateTemp("", "test.key")
assert.Nil(t, err)
os.Remove(keyF.Name())

Expand All @@ -120,7 +119,7 @@ func Test_ca(t *testing.T) {
assert.Equal(t, "", eb.String())

// create temp cert file
crtF, err := ioutil.TempFile("", "test.crt")
crtF, err := os.CreateTemp("", "test.crt")
assert.Nil(t, err)
os.Remove(crtF.Name())
os.Remove(keyF.Name())
Expand All @@ -134,13 +133,13 @@ func Test_ca(t *testing.T) {
assert.Equal(t, "", eb.String())

// read cert and key files
rb, _ := ioutil.ReadFile(keyF.Name())
rb, _ := os.ReadFile(keyF.Name())
lKey, b, err := cert.UnmarshalEd25519PrivateKey(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
assert.Len(t, lKey, 64)

rb, _ = ioutil.ReadFile(crtF.Name())
rb, _ = os.ReadFile(crtF.Name())
lCrt, b, err := cert.UnmarshalNebulaCertificateFromPEM(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
Expand All @@ -166,7 +165,7 @@ func Test_ca(t *testing.T) {
assert.Equal(t, "", eb.String())

// read encrypted key file and verify default params
rb, _ = ioutil.ReadFile(keyF.Name())
rb, _ = os.ReadFile(keyF.Name())
k, _ := pem.Decode(rb)
ned, err := cert.UnmarshalNebulaEncryptedData(k.Bytes)
assert.Nil(t, err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/nebula-cert/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/slackhq/nebula/cert"
Expand Down Expand Up @@ -54,12 +53,12 @@ func keygen(args []string, out io.Writer, errOut io.Writer) error {
return fmt.Errorf("invalid curve: %s", *cf.curve)
}

err = ioutil.WriteFile(*cf.outKeyPath, cert.MarshalPrivateKey(curve, rawPriv), 0600)
err = os.WriteFile(*cf.outKeyPath, cert.MarshalPrivateKey(curve, rawPriv), 0600)
if err != nil {
return fmt.Errorf("error while writing out-key: %s", err)
}

err = ioutil.WriteFile(*cf.outPubPath, cert.MarshalPublicKey(curve, pub), 0600)
err = os.WriteFile(*cf.outPubPath, cert.MarshalPublicKey(curve, pub), 0600)
if err != nil {
return fmt.Errorf("error while writing out-pub: %s", err)
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/nebula-cert/keygen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

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

Expand Down Expand Up @@ -54,7 +53,7 @@ func Test_keygen(t *testing.T) {
assert.Equal(t, "", eb.String())

// create temp key file
keyF, err := ioutil.TempFile("", "test.key")
keyF, err := os.CreateTemp("", "test.key")
assert.Nil(t, err)
defer os.Remove(keyF.Name())

Expand All @@ -67,7 +66,7 @@ func Test_keygen(t *testing.T) {
assert.Equal(t, "", eb.String())

// create temp pub file
pubF, err := ioutil.TempFile("", "test.pub")
pubF, err := os.CreateTemp("", "test.pub")
assert.Nil(t, err)
defer os.Remove(pubF.Name())

Expand All @@ -80,13 +79,13 @@ func Test_keygen(t *testing.T) {
assert.Equal(t, "", eb.String())

// read cert and key files
rb, _ := ioutil.ReadFile(keyF.Name())
rb, _ := os.ReadFile(keyF.Name())
lKey, b, err := cert.UnmarshalX25519PrivateKey(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
assert.Len(t, lKey, 32)

rb, _ = ioutil.ReadFile(pubF.Name())
rb, _ = os.ReadFile(pubF.Name())
lPub, b, err := cert.UnmarshalX25519PublicKey(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/nebula-cert/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -41,7 +40,7 @@ func printCert(args []string, out io.Writer, errOut io.Writer) error {
return err
}

rawCert, err := ioutil.ReadFile(*pf.path)
rawCert, err := os.ReadFile(*pf.path)
if err != nil {
return fmt.Errorf("unable to read cert; %s", err)
}
Expand Down Expand Up @@ -87,7 +86,7 @@ func printCert(args []string, out io.Writer, errOut io.Writer) error {
return fmt.Errorf("error while generating qr code: %s", err)
}

err = ioutil.WriteFile(*pf.outQRPath, b, 0600)
err = os.WriteFile(*pf.outQRPath, b, 0600)
if err != nil {
return fmt.Errorf("error while writing out-qr: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/nebula-cert/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -54,7 +53,7 @@ func Test_printCert(t *testing.T) {
// invalid cert at path
ob.Reset()
eb.Reset()
tf, err := ioutil.TempFile("", "print-cert")
tf, err := os.CreateTemp("", "print-cert")
assert.Nil(t, err)
defer os.Remove(tf.Name())

Expand Down
13 changes: 6 additions & 7 deletions cmd/nebula-cert/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
Expand Down Expand Up @@ -73,7 +72,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return newHelpErrorf("cannot set both -in-pub and -out-key")
}

rawCAKey, err := ioutil.ReadFile(*sf.caKeyPath)
rawCAKey, err := os.ReadFile(*sf.caKeyPath)
if err != nil {
return fmt.Errorf("error while reading ca-key: %s", err)
}
Expand Down Expand Up @@ -112,7 +111,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return fmt.Errorf("error while parsing ca-key: %s", err)
}

rawCACert, err := ioutil.ReadFile(*sf.caCertPath)
rawCACert, err := os.ReadFile(*sf.caCertPath)
if err != nil {
return fmt.Errorf("error while reading ca-crt: %s", err)
}
Expand Down Expand Up @@ -178,7 +177,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)

var pub, rawPriv []byte
if *sf.inPubPath != "" {
rawPub, err := ioutil.ReadFile(*sf.inPubPath)
rawPub, err := os.ReadFile(*sf.inPubPath)
if err != nil {
return fmt.Errorf("error while reading in-pub: %s", err)
}
Expand Down Expand Up @@ -235,7 +234,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return fmt.Errorf("refusing to overwrite existing key: %s", *sf.outKeyPath)
}

err = ioutil.WriteFile(*sf.outKeyPath, cert.MarshalPrivateKey(curve, rawPriv), 0600)
err = os.WriteFile(*sf.outKeyPath, cert.MarshalPrivateKey(curve, rawPriv), 0600)
if err != nil {
return fmt.Errorf("error while writing out-key: %s", err)
}
Expand All @@ -246,7 +245,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return fmt.Errorf("error while marshalling certificate: %s", err)
}

err = ioutil.WriteFile(*sf.outCertPath, b, 0600)
err = os.WriteFile(*sf.outCertPath, b, 0600)
if err != nil {
return fmt.Errorf("error while writing out-crt: %s", err)
}
Expand All @@ -257,7 +256,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return fmt.Errorf("error while generating qr code: %s", err)
}

err = ioutil.WriteFile(*sf.outQRPath, b, 0600)
err = os.WriteFile(*sf.outQRPath, b, 0600)
if err != nil {
return fmt.Errorf("error while writing out-qr: %s", err)
}
Expand Down
23 changes: 11 additions & 12 deletions cmd/nebula-cert/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"crypto/rand"
"errors"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -104,7 +103,7 @@ func Test_signCert(t *testing.T) {
// failed to unmarshal key
ob.Reset()
eb.Reset()
caKeyF, err := ioutil.TempFile("", "sign-cert.key")
caKeyF, err := os.CreateTemp("", "sign-cert.key")
assert.Nil(t, err)
defer os.Remove(caKeyF.Name())

Expand All @@ -128,7 +127,7 @@ func Test_signCert(t *testing.T) {
// failed to unmarshal cert
ob.Reset()
eb.Reset()
caCrtF, err := ioutil.TempFile("", "sign-cert.crt")
caCrtF, err := os.CreateTemp("", "sign-cert.crt")
assert.Nil(t, err)
defer os.Remove(caCrtF.Name())

Expand Down Expand Up @@ -159,7 +158,7 @@ func Test_signCert(t *testing.T) {
// failed to unmarshal pub
ob.Reset()
eb.Reset()
inPubF, err := ioutil.TempFile("", "in.pub")
inPubF, err := os.CreateTemp("", "in.pub")
assert.Nil(t, err)
defer os.Remove(inPubF.Name())

Expand Down Expand Up @@ -206,7 +205,7 @@ func Test_signCert(t *testing.T) {

// mismatched ca key
_, caPriv2, _ := ed25519.GenerateKey(rand.Reader)
caKeyF2, err := ioutil.TempFile("", "sign-cert-2.key")
caKeyF2, err := os.CreateTemp("", "sign-cert-2.key")
assert.Nil(t, err)
defer os.Remove(caKeyF2.Name())
caKeyF2.Write(cert.MarshalEd25519PrivateKey(caPriv2))
Expand All @@ -227,7 +226,7 @@ func Test_signCert(t *testing.T) {
assert.Empty(t, eb.String())

// create temp key file
keyF, err := ioutil.TempFile("", "test.key")
keyF, err := os.CreateTemp("", "test.key")
assert.Nil(t, err)
os.Remove(keyF.Name())

Expand All @@ -241,7 +240,7 @@ func Test_signCert(t *testing.T) {
os.Remove(keyF.Name())

// create temp cert file
crtF, err := ioutil.TempFile("", "test.crt")
crtF, err := os.CreateTemp("", "test.crt")
assert.Nil(t, err)
os.Remove(crtF.Name())

Expand All @@ -254,13 +253,13 @@ func Test_signCert(t *testing.T) {
assert.Empty(t, eb.String())

// read cert and key files
rb, _ := ioutil.ReadFile(keyF.Name())
rb, _ := os.ReadFile(keyF.Name())
lKey, b, err := cert.UnmarshalX25519PrivateKey(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
assert.Len(t, lKey, 32)

rb, _ = ioutil.ReadFile(crtF.Name())
rb, _ = os.ReadFile(crtF.Name())
lCrt, b, err := cert.UnmarshalNebulaCertificateFromPEM(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
Expand Down Expand Up @@ -296,7 +295,7 @@ func Test_signCert(t *testing.T) {
assert.Empty(t, eb.String())

// read cert file and check pub key matches in-pub
rb, _ = ioutil.ReadFile(crtF.Name())
rb, _ = os.ReadFile(crtF.Name())
lCrt, b, err = cert.UnmarshalNebulaCertificateFromPEM(rb)
assert.Len(t, b, 0)
assert.Nil(t, err)
Expand Down Expand Up @@ -348,11 +347,11 @@ func Test_signCert(t *testing.T) {
ob.Reset()
eb.Reset()

caKeyF, err = ioutil.TempFile("", "sign-cert.key")
caKeyF, err = os.CreateTemp("", "sign-cert.key")
assert.Nil(t, err)
defer os.Remove(caKeyF.Name())

caCrtF, err = ioutil.TempFile("", "sign-cert.crt")
caCrtF, err = os.CreateTemp("", "sign-cert.crt")
assert.Nil(t, err)
defer os.Remove(caCrtF.Name())

Expand Down
5 changes: 2 additions & 3 deletions cmd/nebula-cert/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -40,7 +39,7 @@ func verify(args []string, out io.Writer, errOut io.Writer) error {
return err
}

rawCACert, err := ioutil.ReadFile(*vf.caPath)
rawCACert, err := os.ReadFile(*vf.caPath)
if err != nil {
return fmt.Errorf("error while reading ca: %s", err)
}
Expand All @@ -57,7 +56,7 @@ func verify(args []string, out io.Writer, errOut io.Writer) error {
}
}

rawCert, err := ioutil.ReadFile(*vf.certPath)
rawCert, err := os.ReadFile(*vf.certPath)
if err != nil {
return fmt.Errorf("unable to read crt; %s", err)
}
Expand Down
Loading