mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-04 03:13:57 +00:00
all: move from io/ioutil to io and os packages (#353)
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>
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -144,7 +143,7 @@ func TestEncryptDecryptX25519(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
outBytes, err := ioutil.ReadAll(out)
|
outBytes, err := io.ReadAll(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -181,7 +180,7 @@ func TestEncryptDecryptScrypt(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
outBytes, err := ioutil.ReadAll(out)
|
outBytes, err := io.ReadAll(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -121,7 +120,7 @@ func testArmor(t *testing.T, size int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := armor.NewReader(buf)
|
r := armor.NewReader(buf)
|
||||||
out, err := ioutil.ReadAll(r)
|
out, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
func TestVectors(t *testing.T) {
|
func TestVectors(t *testing.T) {
|
||||||
var defaultIDs []age.Identity
|
var defaultIDs []age.Identity
|
||||||
|
|
||||||
password, err := ioutil.ReadFile("testdata/default_password.txt")
|
password, err := os.ReadFile("testdata/default_password.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func TestVectors(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
identities = ids
|
identities = ids
|
||||||
}
|
}
|
||||||
password, err := ioutil.ReadFile("testdata/" + name + "_password.txt")
|
password, err := os.ReadFile("testdata/" + name + "_password.txt")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
p := strings.TrimSpace(string(password))
|
p := strings.TrimSpace(string(password))
|
||||||
i, err := age.NewScryptIdentity(p)
|
i, err := age.NewScryptIdentity(p)
|
||||||
@@ -81,7 +81,7 @@ func TestVectors(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
out, err := ioutil.ReadAll(r)
|
out, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -153,7 +152,7 @@ func parseIdentitiesFile(name string) ([]age.Identity, error) {
|
|||||||
r = armor.NewReader(r)
|
r = armor.NewReader(r)
|
||||||
}
|
}
|
||||||
const privateKeySizeLimit = 1 << 24 // 16 MiB
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read %q: %v", name, err)
|
return nil, fmt.Errorf("failed to read %q: %v", name, err)
|
||||||
}
|
}
|
||||||
@@ -177,7 +176,7 @@ func parseIdentitiesFile(name string) ([]age.Identity, error) {
|
|||||||
// Another PEM file, possibly an SSH private key.
|
// Another PEM file, possibly an SSH private key.
|
||||||
case strings.HasPrefix(peeked, "-----BEGIN"):
|
case strings.HasPrefix(peeked, "-----BEGIN"):
|
||||||
const privateKeySizeLimit = 1 << 14 // 16 KiB
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read %q: %v", name, err)
|
return nil, fmt.Errorf("failed to read %q: %v", name, err)
|
||||||
}
|
}
|
||||||
@@ -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)
|
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()
|
defer f.Close()
|
||||||
contents, err := ioutil.ReadAll(f)
|
contents, err := io.ReadAll(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read %q: %v", name+".pub", err)
|
return nil, fmt.Errorf("failed to read %q: %v", name+".pub", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user