Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: replace io/ioutil with io and os package #230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions acme/autocert/autocert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"crypto/x509/pkix"
"encoding/asn1"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -941,7 +941,7 @@ func TestEndToEndALPN(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -995,7 +995,7 @@ func TestEndToEndHTTP(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions acme/autocert/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package autocert
import (
"context"
"errors"
"io/ioutil"
"os"
"path/filepath"
)
Expand Down Expand Up @@ -48,7 +47,7 @@ func (d DirCache) Get(ctx context.Context, name string) ([]byte, error) {
done = make(chan struct{})
)
go func() {
data, err = ioutil.ReadFile(name)
data, err = os.ReadFile(name)
close(done)
}()
select {
Expand Down Expand Up @@ -119,7 +118,7 @@ func (d DirCache) Delete(ctx context.Context, name string) error {
// writeTempFile writes b to a temporary file, closes the file and returns its path.
func (d DirCache) writeTempFile(prefix string, b []byte) (name string, reterr error) {
// TempFile uses 0600 permissions
f, err := ioutil.TempFile(string(d), prefix)
f, err := os.CreateTemp(string(d), prefix)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions acme/autocert/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package autocert

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand All @@ -17,7 +16,7 @@ import (
var _ Cache = DirCache("/")

func TestDirCache(t *testing.T) {
dir, err := ioutil.TempDir("", "autocert")
dir, err := os.MkdirTemp("", "autocert")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions acme/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"strconv"
Expand Down Expand Up @@ -310,7 +310,7 @@ func isRetriable(code int) bool {
func responseError(resp *http.Response) error {
// don't care if ReadAll returns an error:
// json.Unmarshal will fail in that case anyway
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
e := &wireError{Status: resp.StatusCode}
if err := json.Unmarshal(b, e); err != nil {
// this is not a regular error response:
Expand Down
4 changes: 2 additions & 2 deletions acme/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package acme
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestErrorResponse(t *testing.T) {
res := &http.Response{
StatusCode: 400,
Status: "400 Bad Request",
Body: ioutil.NopCloser(strings.NewReader(s)),
Body: io.NopCloser(strings.NewReader(s)),
Header: http.Header{"X-Foo": {"bar"}},
}
err := responseError(res)
Expand Down
5 changes: 2 additions & 3 deletions acme/rfc8555.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"
)
Expand Down Expand Up @@ -390,7 +389,7 @@ func (c *Client) fetchCertRFC(ctx context.Context, url string, bundle bool) ([][
// Get all the bytes up to a sane maximum.
// Account very roughly for base64 overhead.
const max = maxCertChainSize + maxCertChainSize/33
b, err := ioutil.ReadAll(io.LimitReader(res.Body, max+1))
b, err := io.ReadAll(io.LimitReader(res.Body, max+1))
if err != nil {
return nil, fmt.Errorf("acme: fetch cert response stream: %v", err)
}
Expand Down Expand Up @@ -469,7 +468,7 @@ func (c *Client) ListCertAlternates(ctx context.Context, url string) ([]string,

// We don't need the body but we need to discard it so we don't end up
// preventing keep-alive
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
if _, err := io.Copy(io.Discard, res.Body); err != nil {
return nil, fmt.Errorf("acme: cert alternates response stream: %v", err)
}
alts := linkHeader(res.Header, "alternate")
Expand Down
14 changes: 7 additions & 7 deletions acme/rfc8555_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestRFC_postKID(t *testing.T) {
w.Header().Set("Location", "/account-1")
w.Write([]byte(`{"status":"valid"}`))
case "/post":
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil {
t.Errorf("decodeJWSHead: %v", err)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestRFC_postKID(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
b, _ := ioutil.ReadAll(res.Body) // don't care about err - just checking b
b, _ := io.ReadAll(res.Body) // don't care about err - just checking b
if string(b) != "pong" {
t.Errorf("res.Body = %q; want pong", b)
}
Expand Down Expand Up @@ -297,7 +297,7 @@ func TestRFC_Register(t *testing.T) {
"orders": %q
}`, email, s.url("/accounts/1/orders"))

b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil {
t.Errorf("decodeJWSHead: %v", err)
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestRFC_UpdateReg(t *testing.T) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status": "valid"}`))

b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil {
t.Errorf("decodeJWSHead: %v", err)
Expand Down Expand Up @@ -668,7 +668,7 @@ func TestRFC_DeactivateReg(t *testing.T) {
Orders: s.url("/accounts/1/orders"),
})

b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil {
t.Errorf("decodeJWSHead: %v", err)
Expand Down Expand Up @@ -700,7 +700,7 @@ func TestRFC_DeactivateReg(t *testing.T) {
})
}
var req account
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil {
t.Errorf("decodeJWSHead: %v", err)
Expand Down
3 changes: 1 addition & 2 deletions internal/wycheproof/wycheproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -62,7 +61,7 @@ func TestMain(m *testing.M) {
}

func readTestVector(t *testing.T, f string, dest interface{}) {
b, err := ioutil.ReadFile(filepath.Join(wycheproofTestVectorsDir, f))
b, err := os.ReadFile(filepath.Join(wycheproofTestVectorsDir, f))
if err != nil {
t.Fatalf("failed to read json file: %v", err)
}
Expand Down
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
3 changes: 1 addition & 2 deletions openpgp/packet/compressed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"encoding/hex"
"io"
"io/ioutil"
"testing"
)

Expand All @@ -25,7 +24,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
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"

"golang.org/x/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 @@ -10,7 +10,6 @@ import (
"fmt"
"golang.org/x/crypto/openpgp/errors"
"io"
"io/ioutil"
"testing"
)

Expand Down Expand Up @@ -100,7 +99,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 @@ -172,7 +171,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 @@ -13,7 +13,6 @@ import (
"crypto/rsa"
"crypto/sha1"
"io"
"io/ioutil"
"math/big"
"strconv"
"time"
Expand Down Expand Up @@ -133,7 +132,7 @@ func (pk *PrivateKey) parse(r io.Reader) (err error) {
}
}

pk.encryptedData, err = ioutil.ReadAll(r)
pk.encryptedData, err = io.ReadAll(r)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions openpgp/packet/signature_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto"
"encoding/hex"
"io"
"io/ioutil"
"testing"

"golang.org/x/crypto/openpgp/armor"
Expand Down Expand Up @@ -45,7 +44,7 @@ func TestSignatureV3Reserialize(t *testing.T) {
t.Errorf("error reserializing: %s", err)
return
}
expected, err := ioutil.ReadAll(v3KeyReader(t))
expected, err := io.ReadAll(v3KeyReader(t))
if err != nil {
t.Error(err)
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 @@ -8,7 +8,6 @@ import (
"bytes"
"encoding/hex"
"io"
"io/ioutil"
"testing"
)

Expand Down Expand Up @@ -46,7 +45,7 @@ func TestSymmetricKeyEncrypted(t *testing.T) {
return
}

contents, err := ioutil.ReadAll(r)
contents, err := io.ReadAll(r)
if err != nil && err != io.EOF {
t.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion openpgp/packet/symmetrically_encrypted.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (w *seMDCWriter) Close() (err error) {
return w.w.Close()
}

// noOpCloser is like an ioutil.NopCloser, but for an io.Writer.
// noOpCloser is like an io.NopCloser, but for an io.Writer.
type noOpCloser struct {
w io.Writer
}
Expand Down
5 changes: 2 additions & 3 deletions openpgp/packet/symmetrically_encrypted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/hex"
"golang.org/x/crypto/openpgp/errors"
"io"
"io/ioutil"
"testing"
)

Expand Down Expand Up @@ -42,7 +41,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 @@ -62,7 +61,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
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 @@ -56,7 +55,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
Loading