Skip to content

Commit

Permalink
refactor: remove ioutil package (#15)
Browse files Browse the repository at this point in the history
This commit removes ioutil package from keygen.go and keygen_test.go.

Signed-off-by: orangekame3 <miya.org.0309@gmail.com>
  • Loading branch information
orangekame3 committed Aug 15, 2024
1 parent 11fd3c7 commit 334fb4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)}
}
Expand Down
6 changes: 3 additions & 3 deletions keygen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"crypto/elliptic"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 334fb4f

Please sign in to comment.