all: replace io/ioutil with io and os package

For golang/go#45557

Change-Id: I447530cc66896aef7a8d528ccb8d095b80e3cf47
GitHub-Last-Rev: 5f385ff46487ac318bd1147cdbbd26bb0ffd0426
GitHub-Pull-Request: golang/crypto#230
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/430797
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
cui fliter
2022-09-19 17:36:07 +00:00
committed by Gopher Robot
parent c86fa9a7ed
commit 35f4265a4b
30 changed files with 60 additions and 83 deletions
+3 -3
View File
@@ -17,7 +17,7 @@ import (
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/asn1" "encoding/asn1"
"fmt" "fmt"
"io/ioutil" "io"
"math/big" "math/big"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@@ -941,7 +941,7 @@ func TestEndToEndALPN(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer res.Body.Close() defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body) b, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -995,7 +995,7 @@ func TestEndToEndHTTP(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer res.Body.Close() defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body) b, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
+2 -3
View File
@@ -7,7 +7,6 @@ package autocert
import ( import (
"context" "context"
"errors" "errors"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
) )
@@ -48,7 +47,7 @@ func (d DirCache) Get(ctx context.Context, name string) ([]byte, error) {
done = make(chan struct{}) done = make(chan struct{})
) )
go func() { go func() {
data, err = ioutil.ReadFile(name) data, err = os.ReadFile(name)
close(done) close(done)
}() }()
select { select {
@@ -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. // 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) { func (d DirCache) writeTempFile(prefix string, b []byte) (name string, reterr error) {
// TempFile uses 0600 permissions // TempFile uses 0600 permissions
f, err := ioutil.TempFile(string(d), prefix) f, err := os.CreateTemp(string(d), prefix)
if err != nil { if err != nil {
return "", err return "", err
} }
+1 -2
View File
@@ -6,7 +6,6 @@ package autocert
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@@ -17,7 +16,7 @@ import (
var _ Cache = DirCache("/") var _ Cache = DirCache("/")
func TestDirCache(t *testing.T) { func TestDirCache(t *testing.T) {
dir, err := ioutil.TempDir("", "autocert") dir, err := os.MkdirTemp("", "autocert")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
+2 -2
View File
@@ -12,7 +12,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"math/big" "math/big"
"net/http" "net/http"
"strconv" "strconv"
@@ -310,7 +310,7 @@ func isRetriable(code int) bool {
func responseError(resp *http.Response) error { func responseError(resp *http.Response) error {
// don't care if ReadAll returns an error: // don't care if ReadAll returns an error:
// json.Unmarshal will fail in that case anyway // json.Unmarshal will fail in that case anyway
b, _ := ioutil.ReadAll(resp.Body) b, _ := io.ReadAll(resp.Body)
e := &wireError{Status: resp.StatusCode} e := &wireError{Status: resp.StatusCode}
if err := json.Unmarshal(b, e); err != nil { if err := json.Unmarshal(b, e); err != nil {
// this is not a regular error response: // this is not a regular error response:
+2 -2
View File
@@ -7,7 +7,7 @@ package acme
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"reflect" "reflect"
@@ -54,7 +54,7 @@ func TestErrorResponse(t *testing.T) {
res := &http.Response{ res := &http.Response{
StatusCode: 400, StatusCode: 400,
Status: "400 Bad Request", Status: "400 Bad Request",
Body: ioutil.NopCloser(strings.NewReader(s)), Body: io.NopCloser(strings.NewReader(s)),
Header: http.Header{"X-Foo": {"bar"}}, Header: http.Header{"X-Foo": {"bar"}},
} }
err := responseError(res) err := responseError(res)
+2 -3
View File
@@ -13,7 +13,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "time"
) )
@@ -390,7 +389,7 @@ func (c *Client) fetchCertRFC(ctx context.Context, url string, bundle bool) ([][
// Get all the bytes up to a sane maximum. // Get all the bytes up to a sane maximum.
// Account very roughly for base64 overhead. // Account very roughly for base64 overhead.
const max = maxCertChainSize + maxCertChainSize/33 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 { if err != nil {
return nil, fmt.Errorf("acme: fetch cert response stream: %v", err) return nil, fmt.Errorf("acme: fetch cert response stream: %v", err)
} }
@@ -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 // We don't need the body but we need to discard it so we don't end up
// preventing keep-alive // 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) return nil, fmt.Errorf("acme: cert alternates response stream: %v", err)
} }
alts := linkHeader(res.Header, "alternate") alts := linkHeader(res.Header, "alternate")
+7 -7
View File
@@ -17,7 +17,7 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"math/big" "math/big"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@@ -148,7 +148,7 @@ func TestRFC_postKID(t *testing.T) {
w.Header().Set("Location", "/account-1") w.Header().Set("Location", "/account-1")
w.Write([]byte(`{"status":"valid"}`)) w.Write([]byte(`{"status":"valid"}`))
case "/post": 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)) head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil { if err != nil {
t.Errorf("decodeJWSHead: %v", err) t.Errorf("decodeJWSHead: %v", err)
@@ -194,7 +194,7 @@ func TestRFC_postKID(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer res.Body.Close() 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" { if string(b) != "pong" {
t.Errorf("res.Body = %q; want pong", b) t.Errorf("res.Body = %q; want pong", b)
} }
@@ -297,7 +297,7 @@ func TestRFC_Register(t *testing.T) {
"orders": %q "orders": %q
}`, email, s.url("/accounts/1/orders")) }`, 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)) head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil { if err != nil {
t.Errorf("decodeJWSHead: %v", err) t.Errorf("decodeJWSHead: %v", err)
@@ -528,7 +528,7 @@ func TestRFC_UpdateReg(t *testing.T) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status": "valid"}`)) 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)) head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil { if err != nil {
t.Errorf("decodeJWSHead: %v", err) t.Errorf("decodeJWSHead: %v", err)
@@ -668,7 +668,7 @@ func TestRFC_DeactivateReg(t *testing.T) {
Orders: s.url("/accounts/1/orders"), 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)) head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil { if err != nil {
t.Errorf("decodeJWSHead: %v", err) t.Errorf("decodeJWSHead: %v", err)
@@ -700,7 +700,7 @@ func TestRFC_DeactivateReg(t *testing.T) {
}) })
} }
var req account 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)) head, err := decodeJWSHead(bytes.NewReader(b))
if err != nil { if err != nil {
t.Errorf("decodeJWSHead: %v", err) t.Errorf("decodeJWSHead: %v", err)
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@@ -62,7 +61,7 @@ func TestMain(m *testing.M) {
} }
func readTestVector(t *testing.T, f string, dest interface{}) { 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 { if err != nil {
t.Fatalf("failed to read json file: %v", err) t.Fatalf("failed to read json file: %v", err)
} }
+2 -2
View File
@@ -7,7 +7,7 @@ package armor
import ( import (
"bytes" "bytes"
"hash/adler32" "hash/adler32"
"io/ioutil" "io"
"testing" "testing"
) )
@@ -29,7 +29,7 @@ func TestDecodeEncode(t *testing.T) {
t.Errorf("result.Header: got:%#v", result.Header) t.Errorf("result.Header: got:%#v", result.Header)
} }
contents, err := ioutil.ReadAll(result.Body) contents, err := io.ReadAll(result.Body)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@@ -25,7 +24,7 @@ func TestCompressed(t *testing.T) {
return return
} }
contents, err := ioutil.ReadAll(c.Body) contents, err := io.ReadAll(c.Body)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
t.Error(err) t.Error(err)
return return
+1 -2
View File
@@ -7,7 +7,6 @@ package packet
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"golang.org/x/crypto/openpgp/errors" "golang.org/x/crypto/openpgp/errors"
) )
@@ -26,7 +25,7 @@ type OpaquePacket struct {
} }
func (op *OpaquePacket) parse(r io.Reader) (err error) { func (op *OpaquePacket) parse(r io.Reader) (err error) {
op.Contents, err = ioutil.ReadAll(r) op.Contents, err = io.ReadAll(r)
return return
} }
+2 -3
View File
@@ -10,7 +10,6 @@ import (
"fmt" "fmt"
"golang.org/x/crypto/openpgp/errors" "golang.org/x/crypto/openpgp/errors"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@@ -100,7 +99,7 @@ var partialLengthReaderTests = []struct {
func TestPartialLengthReader(t *testing.T) { func TestPartialLengthReader(t *testing.T) {
for i, test := range partialLengthReaderTests { for i, test := range partialLengthReaderTests {
r := &partialLengthReader{readerFromHex(test.hexInput), 0, true} r := &partialLengthReader{readerFromHex(test.hexInput), 0, true}
out, err := ioutil.ReadAll(r) out, err := io.ReadAll(r)
if test.err != nil { if test.err != nil {
if err != test.err { if err != test.err {
t.Errorf("%d: expected different error got:%s want:%s", i, err, test.err) t.Errorf("%d: expected different error got:%s want:%s", i, err, test.err)
@@ -172,7 +171,7 @@ func TestReadHeader(t *testing.T) {
continue continue
} }
body, err := ioutil.ReadAll(contents) body, err := io.ReadAll(contents)
if err != nil { if err != nil {
if !test.unexpectedEOF || err != io.ErrUnexpectedEOF { if !test.unexpectedEOF || err != io.ErrUnexpectedEOF {
t.Errorf("%d: unexpected error from contents: %s", i, err) t.Errorf("%d: unexpected error from contents: %s", i, err)
+1 -2
View File
@@ -13,7 +13,6 @@ import (
"crypto/rsa" "crypto/rsa"
"crypto/sha1" "crypto/sha1"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"strconv" "strconv"
"time" "time"
@@ -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 { if err != nil {
return return
} }
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"crypto" "crypto"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"testing" "testing"
"golang.org/x/crypto/openpgp/armor" "golang.org/x/crypto/openpgp/armor"
@@ -45,7 +44,7 @@ func TestSignatureV3Reserialize(t *testing.T) {
t.Errorf("error reserializing: %s", err) t.Errorf("error reserializing: %s", err)
return return
} }
expected, err := ioutil.ReadAll(v3KeyReader(t)) expected, err := io.ReadAll(v3KeyReader(t))
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
@@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@@ -46,7 +45,7 @@ func TestSymmetricKeyEncrypted(t *testing.T) {
return return
} }
contents, err := ioutil.ReadAll(r) contents, err := io.ReadAll(r)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
t.Error(err) t.Error(err)
return return
+1 -1
View File
@@ -236,7 +236,7 @@ func (w *seMDCWriter) Close() (err error) {
return w.w.Close() 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 { type noOpCloser struct {
w io.Writer w io.Writer
} }
@@ -10,7 +10,6 @@ import (
"encoding/hex" "encoding/hex"
"golang.org/x/crypto/openpgp/errors" "golang.org/x/crypto/openpgp/errors"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@@ -42,7 +41,7 @@ func testMDCReader(t *testing.T) {
for stride := 1; stride < len(mdcPlaintext)/2; stride++ { for stride := 1; stride < len(mdcPlaintext)/2; stride++ {
r := &testReader{data: mdcPlaintext, stride: stride} r := &testReader{data: mdcPlaintext, stride: stride}
mdcReader := &seMDCReader{in: r, h: sha1.New()} mdcReader := &seMDCReader{in: r, h: sha1.New()}
body, err := ioutil.ReadAll(mdcReader) body, err := io.ReadAll(mdcReader)
if err != nil { if err != nil {
t.Errorf("stride: %d, error: %s", stride, err) t.Errorf("stride: %d, error: %s", stride, err)
continue continue
@@ -62,7 +61,7 @@ func testMDCReader(t *testing.T) {
r := &testReader{data: mdcPlaintext, stride: 2} r := &testReader{data: mdcPlaintext, stride: 2}
mdcReader := &seMDCReader{in: r, h: sha1.New()} mdcReader := &seMDCReader{in: r, h: sha1.New()}
_, err := ioutil.ReadAll(mdcReader) _, err := io.ReadAll(mdcReader)
if err != nil { if err != nil {
t.Errorf("corruption test, error: %s", err) t.Errorf("corruption test, error: %s", err)
return return
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"image" "image"
"image/jpeg" "image/jpeg"
"io" "io"
"io/ioutil"
) )
const UserAttrImageSubpacket = 1 const UserAttrImageSubpacket = 1
@@ -56,7 +55,7 @@ func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute {
func (uat *UserAttribute) parse(r io.Reader) (err error) { func (uat *UserAttribute) parse(r io.Reader) (err error) {
// RFC 4880, section 5.13 // RFC 4880, section 5.13
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
return return
} }
+1 -2
View File
@@ -6,7 +6,6 @@ package packet
import ( import (
"io" "io"
"io/ioutil"
"strings" "strings"
) )
@@ -66,7 +65,7 @@ func NewUserId(name, comment, email string) *UserId {
func (uid *UserId) parse(r io.Reader) (err error) { func (uid *UserId) parse(r io.Reader) (err error) {
// RFC 4880, section 5.11 // RFC 4880, section 5.11
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
return return
} }
+5 -6
View File
@@ -9,7 +9,6 @@ import (
_ "crypto/sha512" _ "crypto/sha512"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"strings" "strings"
"testing" "testing"
@@ -128,7 +127,7 @@ func checkSignedMessage(t *testing.T, signedHex, expected string) {
t.Errorf("bad MessageDetails: %#v", md) t.Errorf("bad MessageDetails: %#v", md)
} }
contents, err := ioutil.ReadAll(md.UnverifiedBody) contents, err := io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Errorf("error reading UnverifiedBody: %s", err) t.Errorf("error reading UnverifiedBody: %s", err)
} }
@@ -221,7 +220,7 @@ func TestSignedEncryptedMessage(t *testing.T) {
t.Errorf("#%d: bad MessageDetails: %#v", i, md) t.Errorf("#%d: bad MessageDetails: %#v", i, md)
} }
contents, err := ioutil.ReadAll(md.UnverifiedBody) contents, err := io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Errorf("#%d: error reading UnverifiedBody: %s", i, err) t.Errorf("#%d: error reading UnverifiedBody: %s", i, err)
} }
@@ -245,7 +244,7 @@ func TestUnspecifiedRecipient(t *testing.T) {
return return
} }
contents, err := ioutil.ReadAll(md.UnverifiedBody) contents, err := io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Errorf("error reading UnverifiedBody: %s", err) t.Errorf("error reading UnverifiedBody: %s", err)
} }
@@ -280,7 +279,7 @@ func TestSymmetricallyEncrypted(t *testing.T) {
return return
} }
contents, err := ioutil.ReadAll(md.UnverifiedBody) contents, err := io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Errorf("ReadAll: %s", err) t.Errorf("ReadAll: %s", err)
} }
@@ -454,7 +453,7 @@ func TestSignatureV3Message(t *testing.T) {
return return
} }
_, err = ioutil.ReadAll(md.UnverifiedBody) _, err = io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
+1 -1
View File
@@ -402,7 +402,7 @@ func (s signatureWriter) Close() error {
return s.encryptedData.Close() return s.encryptedData.Close()
} }
// noOpCloser is like an ioutil.NopCloser, but for an io.Writer. // noOpCloser is like an io.NopCloser, but for an io.Writer.
// TODO: we have two of these in OpenPGP packages alone. This probably needs // TODO: we have two of these in OpenPGP packages alone. This probably needs
// to be promoted somewhere more common. // to be promoted somewhere more common.
type noOpCloser struct { type noOpCloser struct {
+2 -3
View File
@@ -7,7 +7,6 @@ package openpgp
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"testing" "testing"
"time" "time"
@@ -245,7 +244,7 @@ func TestEncryption(t *testing.T) {
} }
} }
plaintext, err := ioutil.ReadAll(md.UnverifiedBody) plaintext, err := io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Errorf("#%d: error reading encrypted contents: %s", i, err) t.Errorf("#%d: error reading encrypted contents: %s", i, err)
continue continue
@@ -342,7 +341,7 @@ func TestSigning(t *testing.T) {
t.Errorf("#%d: failed to find the signing Entity", i) t.Errorf("#%d: failed to find the signing Entity", i)
} }
plaintext, err := ioutil.ReadAll(md.UnverifiedBody) plaintext, err := io.ReadAll(md.UnverifiedBody)
if err != nil { if err != nil {
t.Errorf("#%d: error reading contents: %v", i, err) t.Errorf("#%d: error reading contents: %v", i, err)
continue continue
+1 -2
View File
@@ -15,7 +15,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"golang.org/x/crypto/chacha20" "golang.org/x/crypto/chacha20"
"golang.org/x/crypto/internal/poly1305" "golang.org/x/crypto/internal/poly1305"
@@ -497,7 +496,7 @@ func (c *cbcCipher) readCipherPacket(seqNum uint32, r io.Reader) ([]byte, error)
// data, to make distinguishing between // data, to make distinguishing between
// failing MAC and failing length check more // failing MAC and failing length check more
// difficult. // difficult.
io.CopyN(ioutil.Discard, r, int64(c.oracleCamouflage)) io.CopyN(io.Discard, r, int64(c.oracleCamouflage))
} }
} }
return p, err return p, err
+3 -4
View File
@@ -8,7 +8,6 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
@@ -24,7 +23,7 @@ func ExampleNewServerConn() {
// Public key authentication is done by comparing // Public key authentication is done by comparing
// the public key of a received connection // the public key of a received connection
// with the entries in the authorized_keys file. // with the entries in the authorized_keys file.
authorizedKeysBytes, err := ioutil.ReadFile("authorized_keys") authorizedKeysBytes, err := os.ReadFile("authorized_keys")
if err != nil { if err != nil {
log.Fatalf("Failed to load authorized_keys, err: %v", err) log.Fatalf("Failed to load authorized_keys, err: %v", err)
} }
@@ -67,7 +66,7 @@ func ExampleNewServerConn() {
}, },
} }
privateBytes, err := ioutil.ReadFile("id_rsa") privateBytes, err := os.ReadFile("id_rsa")
if err != nil { if err != nil {
log.Fatal("Failed to load private key: ", err) log.Fatal("Failed to load private key: ", err)
} }
@@ -225,7 +224,7 @@ func ExamplePublicKeys() {
// //
// If you have an encrypted private key, the crypto/x509 package // If you have an encrypted private key, the crypto/x509 package
// can be used to decrypt it. // can be used to decrypt it.
key, err := ioutil.ReadFile("/home/user/.ssh/id_rsa") key, err := os.ReadFile("/home/user/.ssh/id_rsa")
if err != nil { if err != nil {
log.Fatalf("unable to read private key: %v", err) log.Fatalf("unable to read private key: %v", err)
} }
+3 -4
View File
@@ -6,7 +6,6 @@ package ssh
import ( import (
"io" "io"
"io/ioutil"
"sync" "sync"
"testing" "testing"
"time" "time"
@@ -73,14 +72,14 @@ func TestMuxChannelExtendedThreadSafety(t *testing.T) {
rd.Add(2) rd.Add(2)
go func() { go func() {
c, err := ioutil.ReadAll(reader) c, err := io.ReadAll(reader)
if string(c) != magic { if string(c) != magic {
t.Fatalf("stdout read got %q, want %q (error %s)", c, magic, err) t.Fatalf("stdout read got %q, want %q (error %s)", c, magic, err)
} }
rd.Done() rd.Done()
}() }()
go func() { go func() {
c, err := ioutil.ReadAll(reader.Stderr()) c, err := io.ReadAll(reader.Stderr())
if string(c) != magic { if string(c) != magic {
t.Fatalf("stderr read got %q, want %q (error %s)", c, magic, err) t.Fatalf("stderr read got %q, want %q (error %s)", c, magic, err)
} }
@@ -670,7 +669,7 @@ func TestZeroWindowAdjust(t *testing.T) {
}() }()
want := "helloworld" want := "helloworld"
c, _ := ioutil.ReadAll(b) c, _ := io.ReadAll(b)
if string(c) != want { if string(c) != want {
t.Errorf("got %q want %q", c, want) t.Errorf("got %q want %q", c, want)
} }
+3 -4
View File
@@ -13,7 +13,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"sync" "sync"
) )
@@ -124,7 +123,7 @@ type Session struct {
// output and error. // output and error.
// //
// If either is nil, Run connects the corresponding file // If either is nil, Run connects the corresponding file
// descriptor to an instance of ioutil.Discard. There is a // descriptor to an instance of io.Discard. There is a
// fixed amount of buffering that is shared for the two streams. // fixed amount of buffering that is shared for the two streams.
// If either blocks it may eventually cause the remote // If either blocks it may eventually cause the remote
// command to block. // command to block.
@@ -506,7 +505,7 @@ func (s *Session) stdout() {
return return
} }
if s.Stdout == nil { if s.Stdout == nil {
s.Stdout = ioutil.Discard s.Stdout = io.Discard
} }
s.copyFuncs = append(s.copyFuncs, func() error { s.copyFuncs = append(s.copyFuncs, func() error {
_, err := io.Copy(s.Stdout, s.ch) _, err := io.Copy(s.Stdout, s.ch)
@@ -519,7 +518,7 @@ func (s *Session) stderr() {
return return
} }
if s.Stderr == nil { if s.Stderr == nil {
s.Stderr = ioutil.Discard s.Stderr = io.Discard
} }
s.copyFuncs = append(s.copyFuncs, func() error { s.copyFuncs = append(s.copyFuncs, func() error {
_, err := io.Copy(s.Stderr, s.ch.Stderr()) _, err := io.Copy(s.Stderr, s.ch.Stderr())
+3 -4
View File
@@ -11,7 +11,6 @@ import (
crypto_rand "crypto/rand" crypto_rand "crypto/rand"
"errors" "errors"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net" "net"
"testing" "testing"
@@ -531,7 +530,7 @@ func sendSignal(signal string, ch Channel, t *testing.T) {
func discardHandler(ch Channel, t *testing.T) { func discardHandler(ch Channel, t *testing.T) {
defer ch.Close() defer ch.Close()
io.Copy(ioutil.Discard, ch) io.Copy(io.Discard, ch)
} }
func echoHandler(ch Channel, in <-chan *Request, t *testing.T) { func echoHandler(ch Channel, in <-chan *Request, t *testing.T) {
@@ -606,7 +605,7 @@ func TestClientWriteEOF(t *testing.T) {
} }
stdin.Close() stdin.Close()
res, err := ioutil.ReadAll(stdout) res, err := io.ReadAll(stdout)
if err != nil { if err != nil {
t.Fatalf("Read failed: %v", err) t.Fatalf("Read failed: %v", err)
} }
@@ -618,7 +617,7 @@ func TestClientWriteEOF(t *testing.T) {
func simpleEchoHandler(ch Channel, in <-chan *Request, t *testing.T) { func simpleEchoHandler(ch Channel, in <-chan *Request, t *testing.T) {
defer ch.Close() defer ch.Close()
data, err := ioutil.ReadAll(ch) data, err := io.ReadAll(ch)
if err != nil { if err != nil {
t.Errorf("handler read error: %v", err) t.Errorf("handler read error: %v", err)
} }
+1 -2
View File
@@ -12,7 +12,6 @@ package test
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"strings" "strings"
"testing" "testing"
@@ -55,7 +54,7 @@ func testDial(t *testing.T, n, listenAddr string, x dialTester) {
} }
x.TestClientConn(t, conn) x.TestClientConn(t, conn)
defer conn.Close() defer conn.Close()
b, err := ioutil.ReadAll(conn) b, err := io.ReadAll(conn)
if err != nil { if err != nil {
t.Fatalf("ReadAll: %v", err) t.Fatalf("ReadAll: %v", err)
} }
+1 -2
View File
@@ -11,7 +11,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net" "net"
"testing" "testing"
@@ -58,7 +57,7 @@ func testPortForward(t *testing.T, n, listenAddr string) {
readChan := make(chan []byte) readChan := make(chan []byte)
go func() { go func() {
data, _ := ioutil.ReadAll(netConn) data, _ := io.ReadAll(netConn)
readChan <- data readChan <- data
}() }()
+3 -4
View File
@@ -14,7 +14,6 @@ import (
"crypto/rand" "crypto/rand"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"os" "os"
@@ -151,7 +150,7 @@ func clientConfig() *ssh.ClientConfig {
// is used for connecting the Go SSH client with sshd without opening // is used for connecting the Go SSH client with sshd without opening
// ports. // ports.
func unixConnection() (*net.UnixConn, *net.UnixConn, error) { func unixConnection() (*net.UnixConn, *net.UnixConn, error) {
dir, err := ioutil.TempDir("", "unixConnection") dir, err := os.MkdirTemp("", "unixConnection")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@@ -316,7 +315,7 @@ func newServerForConfig(t *testing.T, config string, configVars map[string]strin
if uname == "root" { if uname == "root" {
t.Skip("skipping test because current user is root") t.Skip("skipping test because current user is root")
} }
dir, err := ioutil.TempDir("", "sshtest") dir, err := os.MkdirTemp("", "sshtest")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -365,7 +364,7 @@ func newServerForConfig(t *testing.T, config string, configVars map[string]strin
} }
func newTempSocket(t *testing.T) (string, func()) { func newTempSocket(t *testing.T) (string, func()) {
dir, err := ioutil.TempDir("", "socket") dir, err := os.MkdirTemp("", "socket")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }