Skip to content

Commit

Permalink
refactor: Replacer ioutil.ReadAll with io.ReadAll
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux committed Jan 17, 2024
1 parent 75630f2 commit 93256de
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 87 deletions.
4 changes: 2 additions & 2 deletions openpgp/armor/armor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package armor
import (
"bytes"
"hash/adler32"
"io/ioutil"
"io"
"testing"
)

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

contents, err := ioutil.ReadAll(result.Body)
contents, err := io.ReadAll(result.Body)
if err != nil {
t.Error(err)
}
Expand Down
7 changes: 3 additions & 4 deletions openpgp/integration_tests/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestEndToEnd(t *testing.T) {
if err != nil {
panic(err)
}
raw, err := ioutil.ReadAll(file)
raw, err := io.ReadAll(file)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -118,7 +117,7 @@ func decryptionTest(t *testing.T, vector testVector, sk openpgp.EntityList) {
t.Fatal(err)
}

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

plaintext, err := ioutil.ReadAll(md.UnverifiedBody)
plaintext, err := io.ReadAll(md.UnverifiedBody)
if err != nil {
t.Fatalf("Error reading encrypted contents: %s", err)
}
Expand Down
7 changes: 3 additions & 4 deletions openpgp/integration_tests/v2/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto"
"encoding/json"
"io"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -50,7 +49,7 @@ func TestEndToEnd(t *testing.T) {
if err != nil {
panic(err)
}
raw, err := ioutil.ReadAll(file)
raw, err := io.ReadAll(file)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -128,7 +127,7 @@ func decryptionTest(t *testing.T, vector testVector, sk openpgp.EntityList) {
t.Fatal(err)
}

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

plaintext, err := ioutil.ReadAll(md.UnverifiedBody)
plaintext, err := io.ReadAll(md.UnverifiedBody)
if err != nil {
t.Fatalf("Error reading encrypted contents: %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions openpgp/packet/compressed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/rand"
"encoding/hex"
"io"
"io/ioutil"
mathrand "math/rand"
"testing"
)
Expand All @@ -31,7 +30,7 @@ func TestCompressed(t *testing.T) {
return
}

contents, err := ioutil.ReadAll(c.Body)
contents, err := io.ReadAll(c.Body)
if err != nil && err != io.EOF {
t.Error(err)
return
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestCompressDecompressRandomizeFast(t *testing.T) {
if !ok {
t.Error("didn't find Compressed packet")
}
contents, err := ioutil.ReadAll(c.Body)
contents, err := io.ReadAll(c.Body)
if err != nil && err != io.EOF {
t.Error(err)
}
Expand Down
3 changes: 1 addition & 2 deletions openpgp/packet/opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package packet
import (
"bytes"
"io"
"io/ioutil"

"github.com/ProtonMail/go-crypto/openpgp/errors"
)
Expand All @@ -26,7 +25,7 @@ type OpaquePacket struct {
}

func (op *OpaquePacket) parse(r io.Reader) (err error) {
op.Contents, err = ioutil.ReadAll(r)
op.Contents, err = io.ReadAll(r)
return
}

Expand Down
5 changes: 2 additions & 3 deletions openpgp/packet/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"testing"

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

body, err := ioutil.ReadAll(contents)
body, err := io.ReadAll(contents)
if err != nil {
if !test.unexpectedEOF || err != io.ErrUnexpectedEOF {
t.Errorf("%d: unexpected error from contents: %s", i, err)
Expand Down
3 changes: 1 addition & 2 deletions openpgp/packet/private_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"crypto/subtle"
"fmt"
"io"
"io/ioutil"
"math/big"
"strconv"
"time"
Expand Down Expand Up @@ -312,7 +311,7 @@ func (pk *PrivateKey) parse(r io.Reader) (err error) {
return
}
} else {
privateKeyData, err = ioutil.ReadAll(r)
privateKeyData, err = io.ReadAll(r)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions openpgp/packet/symmetric_key_encrypted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/rand"
"encoding/hex"
"io"
"io/ioutil"
mathrand "math/rand"
"testing"

Expand Down Expand Up @@ -55,7 +54,7 @@ func TestDecryptSymmetricKeyAndEncryptedDataPacket(t *testing.T) {
t.Fatal(err)
}

contents, err := ioutil.ReadAll(r)
contents, err := io.ReadAll(r)
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions openpgp/packet/symmetrically_encrypted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/hex"
goerrors "errors"
"io"
"io/ioutil"
"testing"

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

r := &testReader{data: mdcPlaintext, stride: 2}
mdcReader := &seMDCReader{in: r, h: sha1.New()}
_, err := ioutil.ReadAll(mdcReader)
_, err := io.ReadAll(mdcReader)
if err != nil {
t.Errorf("corruption test, error: %s", err)
return
Expand Down Expand Up @@ -200,7 +199,7 @@ func TestAeadRfcVector(t *testing.T) {
return
}

decrypted, err := ioutil.ReadAll(aeadReader)
decrypted, err := io.ReadAll(aeadReader)
if err != nil {
t.Errorf("error when reading: %s", err)
return
Expand Down
3 changes: 1 addition & 2 deletions openpgp/packet/userattribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"image"
"image/jpeg"
"io"
"io/ioutil"
)

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

func (uat *UserAttribute) parse(r io.Reader) (err error) {
// RFC 4880, section 5.13
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions openpgp/packet/userid.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package packet

import (
"io"
"io/ioutil"
"strings"
)

Expand Down Expand Up @@ -66,7 +65,7 @@ func NewUserId(name, comment, email string) *UserId {

func (uid *UserId) parse(r io.Reader) (err error) {
// RFC 4880, section 5.11
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 93256de

Please sign in to comment.