all: replace uses of ioutil with io and os (#24869)

This commit is contained in:
Håvard Anda Estensen
2022-05-16 11:59:35 +02:00
committed by GitHub
parent 330e53fbb9
commit 07508ac0e9
97 changed files with 203 additions and 257 deletions
+1 -2
View File
@@ -26,7 +26,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"math/big"
"os"
@@ -250,7 +249,7 @@ func checkKeyFileEnd(r *bufio.Reader) error {
// restrictive permissions. The key data is saved hex-encoded.
func SaveECDSA(file string, key *ecdsa.PrivateKey) error {
k := hex.EncodeToString(FromECDSA(key))
return ioutil.WriteFile(file, []byte(k), 0600)
return os.WriteFile(file, []byte(k), 0600)
}
// GenerateKey generates a new private key.
+2 -3
View File
@@ -20,7 +20,6 @@ import (
"bytes"
"crypto/ecdsa"
"encoding/hex"
"io/ioutil"
"math/big"
"os"
"reflect"
@@ -182,7 +181,7 @@ func TestLoadECDSA(t *testing.T) {
}
for _, test := range tests {
f, err := ioutil.TempFile("", "loadecdsa_test.*.txt")
f, err := os.CreateTemp("", "loadecdsa_test.*.txt")
if err != nil {
t.Fatal(err)
}
@@ -203,7 +202,7 @@ func TestLoadECDSA(t *testing.T) {
}
func TestSaveECDSA(t *testing.T) {
f, err := ioutil.TempFile("", "saveecdsa_test.*.txt")
f, err := os.CreateTemp("", "saveecdsa_test.*.txt")
if err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -25,7 +25,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
)
@@ -68,7 +68,7 @@ func SignFile(input string, output string, key string, untrustedComment string,
trustedComment = fmt.Sprintf("timestamp:%d", time.Now().Unix())
}
filedata, err := ioutil.ReadFile(input)
filedata, err := os.ReadFile(input)
if err != nil {
return err
}
@@ -96,5 +96,5 @@ func SignFile(input string, output string, key string, untrustedComment string,
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(dataSig))
fmt.Fprintln(out, "trusted comment:", trustedComment)
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(commentSig))
return ioutil.WriteFile(output, out.Bytes(), 0644)
return os.WriteFile(output, out.Bytes(), 0644)
}
+3 -4
View File
@@ -22,7 +22,6 @@ package signify
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -35,7 +34,7 @@ func Fuzz(data []byte) int {
if len(data) < 32 {
return -1
}
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
if err != nil {
panic(err)
}
@@ -76,7 +75,7 @@ func Fuzz(data []byte) int {
// Write the public key into the file to pass it as
// an argument to signify-openbsd
pubKeyFile, err := ioutil.TempFile("", "")
pubKeyFile, err := os.CreateTemp("", "")
if err != nil {
panic(err)
}
@@ -128,7 +127,7 @@ func getKey(fileS string) (string, error) {
func createKeyPair() (string, string) {
// Create key and put it in correct format
tmpKey, err := ioutil.TempFile("", "")
tmpKey, err := os.CreateTemp("", "")
if err != nil {
panic(err)
}
+4 -5
View File
@@ -20,7 +20,6 @@
package signify
import (
"io/ioutil"
"math/rand"
"os"
"testing"
@@ -35,7 +34,7 @@ var (
)
func TestSignify(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -79,7 +78,7 @@ func TestSignify(t *testing.T) {
}
func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -104,7 +103,7 @@ func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
}
func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -129,7 +128,7 @@ func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
}
func TestSignifyTrustedCommentEmpty(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}