Skip to content

Commit 93256de

Browse files
committed
refactor: Replacer ioutil.ReadAll with io.ReadAll
1 parent 75630f2 commit 93256de

15 files changed

+75
-87
lines changed

openpgp/armor/armor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package armor
77
import (
88
"bytes"
99
"hash/adler32"
10-
"io/ioutil"
10+
"io"
1111
"testing"
1212
)
1313

@@ -29,7 +29,7 @@ func TestDecodeEncode(t *testing.T) {
2929
t.Errorf("result.Header: got:%#v", result.Header)
3030
}
3131

32-
contents, err := ioutil.ReadAll(result.Body)
32+
contents, err := io.ReadAll(result.Body)
3333
if err != nil {
3434
t.Error(err)
3535
}

openpgp/integration_tests/end_to_end_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"bytes"
77
"encoding/json"
88
"io"
9-
"io/ioutil"
109
"os"
1110
"strings"
1211
"testing"
@@ -42,7 +41,7 @@ func TestEndToEnd(t *testing.T) {
4241
if err != nil {
4342
panic(err)
4443
}
45-
raw, err := ioutil.ReadAll(file)
44+
raw, err := io.ReadAll(file)
4645
if err != nil {
4746
panic(err)
4847
}
@@ -118,7 +117,7 @@ func decryptionTest(t *testing.T, vector testVector, sk openpgp.EntityList) {
118117
t.Fatal(err)
119118
}
120119

121-
body, err := ioutil.ReadAll(md.UnverifiedBody)
120+
body, err := io.ReadAll(md.UnverifiedBody)
122121
if err != nil {
123122
t.Fatal(err)
124123
}
@@ -218,7 +217,7 @@ func encDecTest(t *testing.T, from testVector, testVectors []testVector) {
218217
t.Fatalf("Failed to find the signing Entity")
219218
}
220219

221-
plaintext, err := ioutil.ReadAll(md.UnverifiedBody)
220+
plaintext, err := io.ReadAll(md.UnverifiedBody)
222221
if err != nil {
223222
t.Fatalf("Error reading encrypted contents: %s", err)
224223
}

openpgp/integration_tests/v2/end_to_end_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"crypto"
88
"encoding/json"
99
"io"
10-
"io/ioutil"
1110
"os"
1211
"strings"
1312
"testing"
@@ -50,7 +49,7 @@ func TestEndToEnd(t *testing.T) {
5049
if err != nil {
5150
panic(err)
5251
}
53-
raw, err := ioutil.ReadAll(file)
52+
raw, err := io.ReadAll(file)
5453
if err != nil {
5554
panic(err)
5655
}
@@ -128,7 +127,7 @@ func decryptionTest(t *testing.T, vector testVector, sk openpgp.EntityList) {
128127
t.Fatal(err)
129128
}
130129

131-
body, err := ioutil.ReadAll(md.UnverifiedBody)
130+
body, err := io.ReadAll(md.UnverifiedBody)
132131
if err != nil {
133132
t.Fatal(err)
134133
}
@@ -235,7 +234,7 @@ func encDecTest(t *testing.T, from testVector, testVectors []testVector) {
235234
t.Fatalf("Failed to find the signing Entity")
236235
}
237236

238-
plaintext, err := ioutil.ReadAll(md.UnverifiedBody)
237+
plaintext, err := io.ReadAll(md.UnverifiedBody)
239238
if err != nil {
240239
t.Fatalf("Error reading encrypted contents: %s", err)
241240
}

openpgp/packet/compressed_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"crypto/rand"
1010
"encoding/hex"
1111
"io"
12-
"io/ioutil"
1312
mathrand "math/rand"
1413
"testing"
1514
)
@@ -31,7 +30,7 @@ func TestCompressed(t *testing.T) {
3130
return
3231
}
3332

34-
contents, err := ioutil.ReadAll(c.Body)
33+
contents, err := io.ReadAll(c.Body)
3534
if err != nil && err != io.EOF {
3635
t.Error(err)
3736
return
@@ -75,7 +74,7 @@ func TestCompressDecompressRandomizeFast(t *testing.T) {
7574
if !ok {
7675
t.Error("didn't find Compressed packet")
7776
}
78-
contents, err := ioutil.ReadAll(c.Body)
77+
contents, err := io.ReadAll(c.Body)
7978
if err != nil && err != io.EOF {
8079
t.Error(err)
8180
}

openpgp/packet/opaque.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package packet
77
import (
88
"bytes"
99
"io"
10-
"io/ioutil"
1110

1211
"github.com/ProtonMail/go-crypto/openpgp/errors"
1312
)
@@ -26,7 +25,7 @@ type OpaquePacket struct {
2625
}
2726

2827
func (op *OpaquePacket) parse(r io.Reader) (err error) {
29-
op.Contents, err = ioutil.ReadAll(r)
28+
op.Contents, err = io.ReadAll(r)
3029
return
3130
}
3231

openpgp/packet/packet_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/hex"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"testing"
1413

1514
"github.com/ProtonMail/go-crypto/openpgp/errors"
@@ -101,7 +100,7 @@ var partialLengthReaderTests = []struct {
101100
func TestPartialLengthReader(t *testing.T) {
102101
for i, test := range partialLengthReaderTests {
103102
r := &partialLengthReader{readerFromHex(test.hexInput), 0, true}
104-
out, err := ioutil.ReadAll(r)
103+
out, err := io.ReadAll(r)
105104
if test.err != nil {
106105
if err != test.err {
107106
t.Errorf("%d: expected different error got:%s want:%s", i, err, test.err)
@@ -173,7 +172,7 @@ func TestReadHeader(t *testing.T) {
173172
continue
174173
}
175174

176-
body, err := ioutil.ReadAll(contents)
175+
body, err := io.ReadAll(contents)
177176
if err != nil {
178177
if !test.unexpectedEOF || err != io.ErrUnexpectedEOF {
179178
t.Errorf("%d: unexpected error from contents: %s", i, err)

openpgp/packet/private_key.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"crypto/subtle"
1616
"fmt"
1717
"io"
18-
"io/ioutil"
1918
"math/big"
2019
"strconv"
2120
"time"
@@ -312,7 +311,7 @@ func (pk *PrivateKey) parse(r io.Reader) (err error) {
312311
return
313312
}
314313
} else {
315-
privateKeyData, err = ioutil.ReadAll(r)
314+
privateKeyData, err = io.ReadAll(r)
316315
if err != nil {
317316
return
318317
}

openpgp/packet/symmetric_key_encrypted_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"crypto/rand"
1010
"encoding/hex"
1111
"io"
12-
"io/ioutil"
1312
mathrand "math/rand"
1413
"testing"
1514

@@ -55,7 +54,7 @@ func TestDecryptSymmetricKeyAndEncryptedDataPacket(t *testing.T) {
5554
t.Fatal(err)
5655
}
5756

58-
contents, err := ioutil.ReadAll(r)
57+
contents, err := io.ReadAll(r)
5958
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
6059
t.Fatal(err)
6160
}

openpgp/packet/symmetrically_encrypted_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"encoding/hex"
1212
goerrors "errors"
1313
"io"
14-
"io/ioutil"
1514
"testing"
1615

1716
"github.com/ProtonMail/go-crypto/openpgp/errors"
@@ -49,7 +48,7 @@ func TestMDCReader(t *testing.T) {
4948
for stride := 1; stride < len(mdcPlaintext)/2; stride++ {
5049
r := &testReader{data: mdcPlaintext, stride: stride}
5150
mdcReader := &seMDCReader{in: r, h: sha1.New()}
52-
body, err := ioutil.ReadAll(mdcReader)
51+
body, err := io.ReadAll(mdcReader)
5352
if err != nil {
5453
t.Errorf("stride: %d, error: %s", stride, err)
5554
continue
@@ -69,7 +68,7 @@ func TestMDCReader(t *testing.T) {
6968

7069
r := &testReader{data: mdcPlaintext, stride: 2}
7170
mdcReader := &seMDCReader{in: r, h: sha1.New()}
72-
_, err := ioutil.ReadAll(mdcReader)
71+
_, err := io.ReadAll(mdcReader)
7372
if err != nil {
7473
t.Errorf("corruption test, error: %s", err)
7574
return
@@ -200,7 +199,7 @@ func TestAeadRfcVector(t *testing.T) {
200199
return
201200
}
202201

203-
decrypted, err := ioutil.ReadAll(aeadReader)
202+
decrypted, err := io.ReadAll(aeadReader)
204203
if err != nil {
205204
t.Errorf("error when reading: %s", err)
206205
return

openpgp/packet/userattribute.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"image"
1010
"image/jpeg"
1111
"io"
12-
"io/ioutil"
1312
)
1413

1514
const UserAttrImageSubpacket = 1
@@ -63,7 +62,7 @@ func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute {
6362

6463
func (uat *UserAttribute) parse(r io.Reader) (err error) {
6564
// RFC 4880, section 5.13
66-
b, err := ioutil.ReadAll(r)
65+
b, err := io.ReadAll(r)
6766
if err != nil {
6867
return
6968
}

0 commit comments

Comments
 (0)