From 334fb4fe9fb3035360e421b305ba68e0834487fc Mon Sep 17 00:00:00 2001 From: Takafumi Miyanaga Date: Fri, 16 Aug 2024 02:22:22 +0900 Subject: [PATCH] refactor: remove ioutil package (#15) This commit removes ioutil package from keygen.go and keygen_test.go. Signed-off-by: orangekame3 --- keygen.go | 5 ++--- keygen_test.go | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/keygen.go b/keygen.go index e0fb009..2535ea5 100644 --- a/keygen.go +++ b/keygen.go @@ -11,7 +11,6 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" "os" "os/user" "path/filepath" @@ -175,7 +174,7 @@ func New(path string, opts ...Option) (*KeyPair, error) { } if s.KeyPairExists() { - privData, err := ioutil.ReadFile(s.privateKeyPath()) + privData, err := os.ReadFile(s.privateKeyPath()) if err != nil { return nil, err } @@ -488,7 +487,7 @@ func (s *KeyPair) KeyPairExists() bool { func writeKeyToFile(keyBytes []byte, path string) error { if _, err := os.Stat(path); os.IsNotExist(err) { - return ioutil.WriteFile(path, keyBytes, 0o600) + return os.WriteFile(path, keyBytes, 0o600) } return FilesystemErr{Err: fmt.Errorf("file %s already exists", path)} } diff --git a/keygen_test.go b/keygen_test.go index bdd695c..65096b6 100644 --- a/keygen_test.go +++ b/keygen_test.go @@ -4,7 +4,7 @@ import ( "bytes" "crypto/elliptic" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -260,7 +260,7 @@ func TestGeneratePublicKeyWithEmptyDir(t *testing.T) { t.Fatalf("error opening SSH key file: %v", err) } defer f.Close() - fc, err := ioutil.ReadAll(f) + fc, err := io.ReadAll(f) if err != nil { t.Fatalf("error reading SSH key file: %v", err) } @@ -289,7 +289,7 @@ func TestGenerateKeyWithPassphrase(t *testing.T) { t.Fatalf("error opening SSH key file: %v", err) } defer f.Close() - fc, err := ioutil.ReadAll(f) + fc, err := io.ReadAll(f) if err != nil { t.Fatalf("error reading SSH key file: %v", err) }