From cffac6e48a80524458034f34a45d2cb9aeaa915a Mon Sep 17 00:00:00 2001 From: Stanislav Kem Date: Sun, 3 Sep 2023 16:09:57 +0200 Subject: [PATCH] fix linter issues --- internal/fsStorage/storage.go | 15 +++++++-------- internal/fsStorage/storage_test.go | 19 +++++++++---------- pkg/pki/pki.go | 12 ------------ 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/internal/fsStorage/storage.go b/internal/fsStorage/storage.go index a0bba3c..0f00d52 100644 --- a/internal/fsStorage/storage.go +++ b/internal/fsStorage/storage.go @@ -10,7 +10,6 @@ import ( "github.com/gofrs/flock" "github.com/kemsta/go-easyrsa/internal/utils" "github.com/kemsta/go-easyrsa/pkg/pair" - "io/ioutil" "math/big" "os" "path/filepath" @@ -107,7 +106,7 @@ func (p *FileSerialProvider) Next() (*big.Int, error) { _ = p.locker.Unlock() }() res := big.NewInt(0) - sBytes, err := ioutil.ReadFile(p.path) + sBytes, err := os.ReadFile(p.path) if os.IsNotExist(err) { // nothing to do. New serial } else if err != nil { @@ -199,11 +198,11 @@ func (s *DirKeyStorage) GetByCN(cn string) ([]*pair.X509Pair, error) { if err != nil { return nil } - certBytes, err := ioutil.ReadFile(path) + certBytes, err := os.ReadFile(path) if err != nil { return nil } - keyBytes, err := ioutil.ReadFile(fmt.Sprintf("%s.key", path[0:len(path)-len(filepath.Ext(path))])) + keyBytes, err := os.ReadFile(fmt.Sprintf("%s.key", path[0:len(path)-len(filepath.Ext(path))])) if err != nil { return nil } @@ -244,11 +243,11 @@ func (s *DirKeyStorage) GetBySerial(serial *big.Int) (*pair.X509Pair, error) { } cn := filepath.Base(filepath.Dir(path)) if serial.Text(16) == big.NewInt(ser).Text(16) { - certBytes, err := ioutil.ReadFile(path) + certBytes, err := os.ReadFile(path) if err != nil { return nil } - keyBytes, err := ioutil.ReadFile(fmt.Sprintf("%s.key", path[0:len(path)-len(filepath.Ext(path))])) + keyBytes, err := os.ReadFile(fmt.Sprintf("%s.key", path[0:len(path)-len(filepath.Ext(path))])) if err != nil { return nil } @@ -278,11 +277,11 @@ func (s *DirKeyStorage) GetAll() ([]*pair.X509Pair, error) { return nil } cn := filepath.Base(filepath.Dir(path)) - certBytes, err := ioutil.ReadFile(path) + certBytes, err := os.ReadFile(path) if err != nil { return nil } - keyBytes, err := ioutil.ReadFile(fmt.Sprintf("%s.key", path[0:len(path)-len(filepath.Ext(path))])) + keyBytes, err := os.ReadFile(fmt.Sprintf("%s.key", path[0:len(path)-len(filepath.Ext(path))])) if err != nil { return nil } diff --git a/internal/fsStorage/storage_test.go b/internal/fsStorage/storage_test.go index 88f41c1..1003225 100644 --- a/internal/fsStorage/storage_test.go +++ b/internal/fsStorage/storage_test.go @@ -7,7 +7,6 @@ import ( "github.com/kemsta/go-easyrsa/internal/utils" "github.com/kemsta/go-easyrsa/pkg/pair" "io" - "io/ioutil" "math/big" "os" "path/filepath" @@ -171,11 +170,11 @@ func TestDirKeyStorage_Put(t *testing.T) { } }) } - certBytes, _ := ioutil.ReadFile(filepath.Join(getTestDir(), "dir_keystorage", "good_cert/42.crt")) + certBytes, _ := os.ReadFile(filepath.Join(getTestDir(), "dir_keystorage", "good_cert/42.crt")) if !bytes.Equal(certBytes, []byte("certbytes")) { t.Errorf("DirKeyStorage.Put() wrong cert bytes in result file") } - keyBytes, _ := ioutil.ReadFile(filepath.Join(getTestDir(), "dir_keystorage", "good_cert/42.key")) + keyBytes, _ := os.ReadFile(filepath.Join(getTestDir(), "dir_keystorage", "good_cert/42.key")) if !bytes.Equal(keyBytes, []byte("keybytes")) { t.Errorf("DirKeyStorage.Put() wrong key bytes in result file") } @@ -340,8 +339,8 @@ func TestDirKeyStorage_GetBySerial(t *testing.T) { func TestDirKeyStorage_DeleteBySerial(t *testing.T) { _ = os.MkdirAll(filepath.Join(getTestDir(), "dir_keystorage", "for_delete"), 0755) - _ = ioutil.WriteFile(filepath.Join(getTestDir(), "dir_keystorage", "for_delete", "a.crt"), []byte(""), 0600) - _ = ioutil.WriteFile(filepath.Join(getTestDir(), "dir_keystorage", "for_delete", "a.key"), []byte(""), 0600) + _ = os.WriteFile(filepath.Join(getTestDir(), "dir_keystorage", "for_delete", "a.crt"), []byte(""), 0600) + _ = os.WriteFile(filepath.Join(getTestDir(), "dir_keystorage", "for_delete", "a.key"), []byte(""), 0600) type fields struct { keydir string @@ -392,7 +391,7 @@ func TestDirKeyStorage_DeleteBySerial(t *testing.T) { func TestFileSerialProvider_Next(t *testing.T) { defer func() { _ = os.RemoveAll(filepath.Join(getTestDir(), "dir_keystorage", "new_serial")) - _ = ioutil.WriteFile(filepath.Join(getTestDir(), "dir_keystorage", "wrong_serial"), []byte("gggg"), 0666) + _ = os.WriteFile(filepath.Join(getTestDir(), "dir_keystorage", "wrong_serial"), []byte("gggg"), 0666) }() type fields struct { path string @@ -463,7 +462,7 @@ func TestFileCRLHolder_Put(t *testing.T) { if err != nil { t.Errorf("FileCRLHolder.Put() error = %v", err) } - got, _ := ioutil.ReadFile(fileName) + got, _ := os.ReadFile(fileName) if !bytes.Equal(got, content) { t.Errorf("FileCRLHolder.Put() got = %v, want %v", got, content) } @@ -472,14 +471,14 @@ func TestFileCRLHolder_Put(t *testing.T) { fileName := filepath.Join(getTestDir(), "dir_keystorage", "exist.pem") content := []byte("content") defer func() { - _ = ioutil.WriteFile(fileName, []byte("asd"), 0644) + _ = os.WriteFile(fileName, []byte("asd"), 0644) }() h := NewFileCRLHolder(fileName) err := h.Put(content) if err != nil { t.Errorf("FileCRLHolder.Put() error = %v", err) } - got, _ := ioutil.ReadFile(fileName) + got, _ := os.ReadFile(fileName) if !bytes.Equal(got, content) { t.Errorf("FileCRLHolder.Put() got = %v, want %v", got, content) } @@ -488,7 +487,7 @@ func TestFileCRLHolder_Put(t *testing.T) { fileName := filepath.Join(getTestDir(), "dir_keystorage", "crl.dir") content := []byte("content") defer func() { - _ = ioutil.WriteFile(fileName, []byte("asd"), 0666) + _ = os.WriteFile(fileName, []byte("asd"), 0666) }() h := NewFileCRLHolder(fileName) err := h.Put(content) diff --git a/pkg/pki/pki.go b/pkg/pki/pki.go index 47202af..403589b 100644 --- a/pkg/pki/pki.go +++ b/pkg/pki/pki.go @@ -299,15 +299,3 @@ func (p *PKI) IsRevoked(serial *big.Int) bool { } return false } - -func removeDups(list []pkix.RevokedCertificate) []pkix.RevokedCertificate { - encountered := map[int64]bool{} - result := make([]pkix.RevokedCertificate, 0) - for _, cert := range list { - if !encountered[cert.SerialNumber.Int64()] { - result = append(result, cert) - encountered[cert.SerialNumber.Int64()] = true - } - } - return result -}