Skip to content

Commit

Permalink
all: move from io/ioutil to io and os packages (#353)
Browse files Browse the repository at this point in the history
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed Dec 18, 2021
1 parent 08f52cc commit 7665b87
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions age_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -144,7 +143,7 @@ func TestEncryptDecryptX25519(t *testing.T) {
if err != nil {
t.Fatal(err)
}
outBytes, err := ioutil.ReadAll(out)
outBytes, err := io.ReadAll(out)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -181,7 +180,7 @@ func TestEncryptDecryptScrypt(t *testing.T) {
if err != nil {
t.Fatal(err)
}
outBytes, err := ioutil.ReadAll(out)
outBytes, err := io.ReadAll(out)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions armor/armor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"log"
"strings"
"testing"
Expand Down Expand Up @@ -121,7 +120,7 @@ func testArmor(t *testing.T, size int) {
}

r := armor.NewReader(buf)
out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/age/age_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

import (
"errors"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand All @@ -18,7 +18,7 @@ import (
func TestVectors(t *testing.T) {
var defaultIDs []age.Identity

password, err := ioutil.ReadFile("testdata/default_password.txt")
password, err := os.ReadFile("testdata/default_password.txt")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestVectors(t *testing.T) {
if err == nil {
identities = ids
}
password, err := ioutil.ReadFile("testdata/" + name + "_password.txt")
password, err := os.ReadFile("testdata/" + name + "_password.txt")
if err == nil {
p := strings.TrimSpace(string(password))
i, err := age.NewScryptIdentity(p)
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestVectors(t *testing.T) {
if err != nil {
t.Fatal(err)
}
out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/age/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -153,7 +152,7 @@ func parseIdentitiesFile(name string) ([]age.Identity, error) {
r = armor.NewReader(r)
}
const privateKeySizeLimit = 1 << 24 // 16 MiB
contents, err := ioutil.ReadAll(io.LimitReader(r, privateKeySizeLimit))
contents, err := io.ReadAll(io.LimitReader(r, privateKeySizeLimit))
if err != nil {
return nil, fmt.Errorf("failed to read %q: %v", name, err)
}
Expand All @@ -177,7 +176,7 @@ func parseIdentitiesFile(name string) ([]age.Identity, error) {
// Another PEM file, possibly an SSH private key.
case strings.HasPrefix(peeked, "-----BEGIN"):
const privateKeySizeLimit = 1 << 14 // 16 KiB
contents, err := ioutil.ReadAll(io.LimitReader(b, privateKeySizeLimit))
contents, err := io.ReadAll(io.LimitReader(b, privateKeySizeLimit))
if err != nil {
return nil, fmt.Errorf("failed to read %q: %v", name, err)
}
Expand Down Expand Up @@ -239,7 +238,7 @@ Use a file for which the corresponding ".pub" file exists, or convert the privat
Ensure %q exists, or convert the private key %q to a modern format with "ssh-keygen -p -m RFC4716"`, name, err, name+".pub", name)
}
defer f.Close()
contents, err := ioutil.ReadAll(f)
contents, err := io.ReadAll(f)
if err != nil {
return nil, fmt.Errorf("failed to read %q: %v", name+".pub", err)
}
Expand Down

0 comments on commit 7665b87

Please sign in to comment.