Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Kem committed Sep 3, 2023
1 parent c870fc7 commit cffac6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
15 changes: 7 additions & 8 deletions internal/fsStorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 9 additions & 10 deletions internal/fsStorage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions pkg/pki/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit cffac6e

Please sign in to comment.