Remove ioutil (#289)

This commit is contained in:
John Wood
2022-08-11 10:59:59 -07:00
committed by GitHub
parent 3041543f46
commit 44210f297c
6 changed files with 36 additions and 41 deletions
+2 -3
View File
@@ -2,7 +2,6 @@ package cli
import (
"crypto/tls"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@@ -170,7 +169,7 @@ Found 1 valid certificate chain(s):
// Test basic dump functionality: Dump a cert
func TestDump(t *testing.T) {
tmpfile, err := ioutil.TempFile("", t.Name())
tmpfile, err := os.CreateTemp("", t.Name())
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
@@ -195,7 +194,7 @@ func TestDumpMissingFile(t *testing.T) {
}
func TestConnect(t *testing.T) {
rootPath, err := ioutil.TempFile("", t.Name())
rootPath, err := os.CreateTemp("", t.Name())
require.NoError(t, err)
defer os.Remove(rootPath.Name())
+3 -3
View File
@@ -21,13 +21,13 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"strings"
)
// LoadPEMKey extracts a private key from a PEM file.
func LoadPEMKey(filename string) (*rsa.PrivateKey, error) {
keyPEMBlock, err := ioutil.ReadFile(filename)
keyPEMBlock, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
@@ -49,7 +49,7 @@ func LoadPEMKey(filename string) (*rsa.PrivateKey, error) {
// LoadPEMCert extracts a certificate from a PEM file.
func LoadPEMCert(filename string) (*x509.Certificate, error) {
certPEMBlock, err := ioutil.ReadFile(filename)
certPEMBlock, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
+2 -3
View File
@@ -28,7 +28,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -211,7 +210,7 @@ func readCertsFromStream(reader io.Reader, filename string, format string, passw
}
return nil
case "DER":
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return fmt.Errorf("unable to read input: %s\n", err)
}
@@ -237,7 +236,7 @@ func readCertsFromStream(reader io.Reader, filename string, format string, passw
}
return fmt.Errorf("unable to parse certificates from DER data\n* X.509 parser gave: %s\n* PKCS7 parser gave: %s\n", err0, err1)
case "PKCS12":
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return fmt.Errorf("unable to read input: %s\n", err)
}
+1 -2
View File
@@ -6,7 +6,6 @@ package ldap
import (
"errors"
"io/ioutil"
"os"
ber "gopkg.in/asn1-ber.v1"
@@ -272,7 +271,7 @@ func addDefaultLDAPResponseDescriptions(packet *ber.Packet) {
// DebugBinaryFile reads and prints packets from the given filename
func DebugBinaryFile(fileName string) error {
file, err := ioutil.ReadFile(fileName)
file, err := os.ReadFile(fileName)
if err != nil {
return NewError(ErrorDebugging, err)
}
+27 -28
View File
@@ -26,26 +26,25 @@ var (
// RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
// Use the key as a value in the DSN where tls=value.
//
// rootCertPool := x509.NewCertPool()
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
// if err != nil {
// log.Fatal(err)
// }
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
// log.Fatal("Failed to append PEM.")
// }
// clientCert := make([]tls.Certificate, 0, 1)
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
// if err != nil {
// log.Fatal(err)
// }
// clientCert = append(clientCert, certs)
// mysql.RegisterTLSConfig("custom", &tls.Config{
// RootCAs: rootCertPool,
// Certificates: clientCert,
// })
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
//
// rootCertPool := x509.NewCertPool()
// pem, err := os.ReadFile("/path/ca-cert.pem")
// if err != nil {
// log.Fatal(err)
// }
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
// log.Fatal("Failed to append PEM.")
// }
// clientCert := make([]tls.Certificate, 0, 1)
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
// if err != nil {
// log.Fatal(err)
// }
// clientCert = append(clientCert, certs)
// mysql.RegisterTLSConfig("custom", &tls.Config{
// RootCAs: rootCertPool,
// Certificates: clientCert,
// })
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
func RegisterTLSConfig(key string, config *tls.Config) error {
if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" {
return fmt.Errorf("key '%s' is reserved", key)
@@ -201,14 +200,14 @@ func scrambleOldPassword(scramble, password []byte) []byte {
// NullTime implements the Scanner interface so
// it can be used as a scan destination:
//
// var nt NullTime
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
// ...
// if nt.Valid {
// // use nt.Time
// } else {
// // NULL value
// }
// var nt NullTime
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
// ...
// if nt.Valid {
// // use nt.Time
// } else {
// // NULL value
// }
//
// This NullTime implementation is not driver-specific
type NullTime struct {
+1 -2
View File
@@ -3,7 +3,6 @@ package pq
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net"
"os"
"os/user"
@@ -108,7 +107,7 @@ func sslCertificateAuthority(tlsConf *tls.Config, o values) {
if sslrootcert := o.Get("sslrootcert"); sslrootcert != "" {
tlsConf.RootCAs = x509.NewCertPool()
cert, err := ioutil.ReadFile(sslrootcert)
cert, err := os.ReadFile(sslrootcert)
if err != nil {
panic(err)
}