diff options
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/md5/gen.go | 4 | ||||
-rw-r--r-- | src/crypto/tls/handshake_test.go | 3 | ||||
-rw-r--r-- | src/crypto/tls/link_test.go | 3 | ||||
-rw-r--r-- | src/crypto/tls/tls.go | 6 | ||||
-rw-r--r-- | src/crypto/x509/name_constraints_test.go | 3 | ||||
-rw-r--r-- | src/crypto/x509/root_ios_gen.go | 4 | ||||
-rw-r--r-- | src/crypto/x509/root_plan9.go | 3 | ||||
-rw-r--r-- | src/crypto/x509/root_unix.go | 25 | ||||
-rw-r--r-- | src/crypto/x509/root_unix_test.go | 5 |
9 files changed, 25 insertions, 31 deletions
diff --git a/src/crypto/md5/gen.go b/src/crypto/md5/gen.go index a11f22059f..1468924cbc 100644 --- a/src/crypto/md5/gen.go +++ b/src/crypto/md5/gen.go @@ -15,8 +15,8 @@ import ( "bytes" "flag" "go/format" - "io/ioutil" "log" + "os" "strings" "text/template" ) @@ -37,7 +37,7 @@ func main() { if err != nil { log.Fatal(err) } - err = ioutil.WriteFile(*filename, data, 0644) + err = os.WriteFile(*filename, data, 0644) if err != nil { log.Fatal(err) } diff --git a/src/crypto/tls/handshake_test.go b/src/crypto/tls/handshake_test.go index 605be587b5..d9ff9fe948 100644 --- a/src/crypto/tls/handshake_test.go +++ b/src/crypto/tls/handshake_test.go @@ -13,7 +13,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net" "os" "os/exec" @@ -224,7 +223,7 @@ func parseTestData(r io.Reader) (flows [][]byte, err error) { // tempFile creates a temp file containing contents and returns its path. func tempFile(contents string) string { - file, err := ioutil.TempFile("", "go-tls-test") + file, err := os.CreateTemp("", "go-tls-test") if err != nil { panic("failed to create temp file: " + err.Error()) } diff --git a/src/crypto/tls/link_test.go b/src/crypto/tls/link_test.go index 8224216b5c..8c392ff7c4 100644 --- a/src/crypto/tls/link_test.go +++ b/src/crypto/tls/link_test.go @@ -7,7 +7,6 @@ package tls import ( "bytes" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -77,7 +76,7 @@ func main() { tls.Dial("", "", nil) } exeFile := filepath.Join(tmpDir, "x.exe") for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := ioutil.WriteFile(goFile, []byte(tt.program), 0644); err != nil { + if err := os.WriteFile(goFile, []byte(tt.program), 0644); err != nil { t.Fatal(err) } os.Remove(exeFile) diff --git a/src/crypto/tls/tls.go b/src/crypto/tls/tls.go index bf577cadea..19884f96e7 100644 --- a/src/crypto/tls/tls.go +++ b/src/crypto/tls/tls.go @@ -22,8 +22,8 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" "net" + "os" "strings" ) @@ -222,11 +222,11 @@ func (d *Dialer) DialContext(ctx context.Context, network, addr string) (net.Con // form a certificate chain. On successful return, Certificate.Leaf will // be nil because the parsed form of the certificate is not retained. func LoadX509KeyPair(certFile, keyFile string) (Certificate, error) { - certPEMBlock, err := ioutil.ReadFile(certFile) + certPEMBlock, err := os.ReadFile(certFile) if err != nil { return Certificate{}, err } - keyPEMBlock, err := ioutil.ReadFile(keyFile) + keyPEMBlock, err := os.ReadFile(keyFile) if err != nil { return Certificate{}, err } diff --git a/src/crypto/x509/name_constraints_test.go b/src/crypto/x509/name_constraints_test.go index 34055d07b5..3826c82c38 100644 --- a/src/crypto/x509/name_constraints_test.go +++ b/src/crypto/x509/name_constraints_test.go @@ -14,7 +14,6 @@ import ( "encoding/hex" "encoding/pem" "fmt" - "io/ioutil" "math/big" "net" "net/url" @@ -2005,7 +2004,7 @@ func TestConstraintCases(t *testing.T) { } func writePEMsToTempFile(certs []*Certificate) *os.File { - file, err := ioutil.TempFile("", "name_constraints_test") + file, err := os.CreateTemp("", "name_constraints_test") if err != nil { panic("cannot create tempfile") } diff --git a/src/crypto/x509/root_ios_gen.go b/src/crypto/x509/root_ios_gen.go index 2bcdab1a77..8bc6e7d9c4 100644 --- a/src/crypto/x509/root_ios_gen.go +++ b/src/crypto/x509/root_ios_gen.go @@ -27,9 +27,9 @@ import ( "fmt" "go/format" "io" - "io/ioutil" "log" "net/http" + "os" "path" "sort" "strings" @@ -155,7 +155,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(*output, source, 0644); err != nil { + if err := os.WriteFile(*output, source, 0644); err != nil { log.Fatal(err) } } diff --git a/src/crypto/x509/root_plan9.go b/src/crypto/x509/root_plan9.go index 09f0e23033..2dc4aaf5d7 100644 --- a/src/crypto/x509/root_plan9.go +++ b/src/crypto/x509/root_plan9.go @@ -7,7 +7,6 @@ package x509 import ( - "io/ioutil" "os" ) @@ -24,7 +23,7 @@ func loadSystemRoots() (*CertPool, error) { roots := NewCertPool() var bestErr error for _, file := range certFiles { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err == nil { roots.AppendCertsFromPEM(data) return roots, nil diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go index 1090b69f83..262fc079d5 100644 --- a/src/crypto/x509/root_unix.go +++ b/src/crypto/x509/root_unix.go @@ -8,7 +8,6 @@ package x509 import ( "io/fs" - "io/ioutil" "os" "path/filepath" "strings" @@ -40,7 +39,7 @@ func loadSystemRoots() (*CertPool, error) { var firstErr error for _, file := range files { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err == nil { roots.AppendCertsFromPEM(data) break @@ -68,7 +67,7 @@ func loadSystemRoots() (*CertPool, error) { continue } for _, fi := range fis { - data, err := ioutil.ReadFile(directory + "/" + fi.Name()) + data, err := os.ReadFile(directory + "/" + fi.Name()) if err == nil { roots.AppendCertsFromPEM(data) } @@ -82,17 +81,17 @@ func loadSystemRoots() (*CertPool, error) { return nil, firstErr } -// readUniqueDirectoryEntries is like ioutil.ReadDir but omits +// readUniqueDirectoryEntries is like os.ReadDir but omits // symlinks that point within the directory. -func readUniqueDirectoryEntries(dir string) ([]fs.FileInfo, error) { - fis, err := ioutil.ReadDir(dir) +func readUniqueDirectoryEntries(dir string) ([]fs.DirEntry, error) { + files, err := os.ReadDir(dir) if err != nil { return nil, err } - uniq := fis[:0] - for _, fi := range fis { - if !isSameDirSymlink(fi, dir) { - uniq = append(uniq, fi) + uniq := files[:0] + for _, f := range files { + if !isSameDirSymlink(f, dir) { + uniq = append(uniq, f) } } return uniq, nil @@ -100,10 +99,10 @@ func readUniqueDirectoryEntries(dir string) ([]fs.FileInfo, error) { // isSameDirSymlink reports whether fi in dir is a symlink with a // target not containing a slash. -func isSameDirSymlink(fi fs.FileInfo, dir string) bool { - if fi.Mode()&fs.ModeSymlink == 0 { +func isSameDirSymlink(f fs.DirEntry, dir string) bool { + if f.Type()&fs.ModeSymlink == 0 { return false } - target, err := os.Readlink(filepath.Join(dir, fi.Name())) + target, err := os.Readlink(filepath.Join(dir, f.Name())) return err == nil && !strings.Contains(target, "/") } diff --git a/src/crypto/x509/root_unix_test.go b/src/crypto/x509/root_unix_test.go index b2e832ff36..878ed7c2fa 100644 --- a/src/crypto/x509/root_unix_test.go +++ b/src/crypto/x509/root_unix_test.go @@ -9,7 +9,6 @@ package x509 import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -147,7 +146,7 @@ func TestLoadSystemCertsLoadColonSeparatedDirs(t *testing.T) { os.Setenv(certFileEnv, origFile) }() - tmpDir, err := ioutil.TempDir(os.TempDir(), "x509-issue35325") + tmpDir, err := os.MkdirTemp(os.TempDir(), "x509-issue35325") if err != nil { t.Fatalf("Failed to create temporary directory: %v", err) } @@ -166,7 +165,7 @@ func TestLoadSystemCertsLoadColonSeparatedDirs(t *testing.T) { t.Fatalf("Failed to create certificate dir: %v", err) } certOutFile := filepath.Join(certDir, "cert.crt") - if err := ioutil.WriteFile(certOutFile, []byte(certPEM), 0655); err != nil { + if err := os.WriteFile(certOutFile, []byte(certPEM), 0655); err != nil { t.Fatalf("Failed to write certificate to file: %v", err) } certDirs = append(certDirs, certDir) |