From eb40c995a3653c72af1aaf0ac612ef4172d48da2 Mon Sep 17 00:00:00 2001 From: Sultan Iman Date: Sat, 22 Jun 2024 18:50:04 +0200 Subject: [PATCH] Upgrade code --- README.md | 4 ++-- canvas/canvas.go | 5 +++-- cmd/classic.go | 5 +++-- cmd/explain.go | 1 + cmd/restore.go | 8 +++----- cmd/root.go | 4 +--- crypto/crypto.go | 3 ++- crypto/crypto_test.go | 3 ++- gen/classic.go | 5 +++-- gen/classic_test.go | 3 ++- main.go | 4 +--- util/image.go | 3 ++- util/rand.go | 6 +----- util/string.go | 6 +----- 14 files changed, 27 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 53771eb..4ce8051 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # PWC -![Tests](https://github.com/imanhodjaev/pwc/actions/workflows/run-tests.yml/badge.svg) + +![Tests](https://github.com/imanhodjaev/pwc/actions/workflows/run-tests.yml/badge.svg) [![CodeQL](https://github.com/sultaniman/pwc/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/sultaniman/pwc/actions/workflows/codeql-analysis.yml) If you need to remember dozens of passwords without having to remember all of them @@ -72,5 +73,4 @@ White #ffffff, Gray #c0c0c0, Red #ffc0c0, Green #c0ffc0, Yellow #ffffc0, Blue #c P.S. it was inspired by https://www.passwordcard.org/en. -

✨ 🚀 ✨

diff --git a/canvas/canvas.go b/canvas/canvas.go index c5f4223..489fe0b 100644 --- a/canvas/canvas.go +++ b/canvas/canvas.go @@ -1,11 +1,12 @@ package canvas import ( + "image" + "strconv" + "github.com/fogleman/gg" "github.com/sultaniman/pwc/util" "golang.org/x/image/font" - "image" - "strconv" ) const ( diff --git a/cmd/classic.go b/cmd/classic.go index 185b3f4..86a085b 100644 --- a/cmd/classic.go +++ b/cmd/classic.go @@ -2,11 +2,12 @@ package cmd import ( "fmt" + "os" + "syscall" + "github.com/spf13/cobra" "github.com/sultaniman/pwc/gen" "github.com/sultaniman/pwc/util" - "os" - "syscall" ) var ( diff --git a/cmd/explain.go b/cmd/explain.go index 5283b94..4ae2f07 100644 --- a/cmd/explain.go +++ b/cmd/explain.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/fatih/color" goc "github.com/gookit/color" "github.com/spf13/cobra" diff --git a/cmd/restore.go b/cmd/restore.go index 3ce9b73..e94f725 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -2,11 +2,11 @@ package cmd import ( "fmt" + "os" + "github.com/spf13/cobra" "github.com/sultaniman/pwc/gen" "github.com/sultaniman/pwc/util" - "io/ioutil" - "os" ) var passphrase string @@ -36,7 +36,7 @@ var restoreCmd = &cobra.Command{ os.Exit(1) } - encryptedBytes, err := ioutil.ReadFile(encryptedFile) + encryptedBytes, err := os.ReadFile(encryptedFile) if err != nil { return err } @@ -73,8 +73,6 @@ var restoreCmd = &cobra.Command{ } return util.SaveImage(canvas.Context, outputFile) - - return nil }, } diff --git a/cmd/root.go b/cmd/root.go index 2f10b08..9c95a8e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,8 +1,6 @@ package cmd -import ( - "github.com/spf13/cobra" -) +import "github.com/spf13/cobra" var rootCmd = &cobra.Command{ Use: "cmd", diff --git a/crypto/crypto.go b/crypto/crypto.go index ad956e9..08a4c12 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -7,8 +7,9 @@ import ( "crypto/sha256" "encoding/hex" "fmt" - "golang.org/x/crypto/pbkdf2" "strings" + + "golang.org/x/crypto/pbkdf2" ) // TODO(thanks): Encryption was adopted from https://gist.github.com/enyachoke/5c60f5eebed693d9b4bacddcad693b47 diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 07e7f53..91056f0 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -1,8 +1,9 @@ package crypto import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestMessageEncryptDecrypt(t *testing.T) { diff --git a/gen/classic.go b/gen/classic.go index 8ad4315..20bf4af 100644 --- a/gen/classic.go +++ b/gen/classic.go @@ -1,11 +1,12 @@ package gen import ( + "image" + "strings" + "github.com/sultaniman/pwc/canvas" "github.com/sultaniman/pwc/crypto" "github.com/sultaniman/pwc/util" - "image" - "strings" ) type ClassicCard struct { diff --git a/gen/classic_test.go b/gen/classic_test.go index d751f9f..858bfdf 100644 --- a/gen/classic_test.go +++ b/gen/classic_test.go @@ -1,9 +1,10 @@ package gen import ( + "testing" + "github.com/stretchr/testify/assert" "github.com/sultaniman/pwc/canvas" - "testing" ) func TestClassicCard_Generate(t *testing.T) { diff --git a/main.go b/main.go index 391a258..b78ab30 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/sultaniman/pwc/cmd" -) +import "github.com/sultaniman/pwc/cmd" func main() { cmd.Execute() diff --git a/util/image.go b/util/image.go index e969db2..1ed86da 100644 --- a/util/image.go +++ b/util/image.go @@ -1,9 +1,10 @@ package util import ( - "github.com/fogleman/gg" "path/filepath" "strings" + + "github.com/fogleman/gg" ) var supportedExtensions = map[string]bool{ diff --git a/util/rand.go b/util/rand.go index 115c6a9..27221d7 100644 --- a/util/rand.go +++ b/util/rand.go @@ -1,9 +1,6 @@ package util -import ( - "math/rand" - "time" -) +import "math/rand" type RandRange struct { Min int @@ -18,6 +15,5 @@ func NewRandRange(min int, max int) *RandRange { } func (rr *RandRange) Next() int { - rand.Seed(time.Now().UnixNano()) return rand.Intn(rr.Max-rr.Min+1) + rr.Min } diff --git a/util/string.go b/util/string.go index 2379e3d..7341de2 100644 --- a/util/string.go +++ b/util/string.go @@ -1,12 +1,8 @@ package util -import ( - "math/rand" - "time" -) +import "math/rand" func Shuffle(inStr string) string { - rand.Seed(time.Now().UnixNano()) inRune := []rune(inStr) rand.Shuffle(len(inRune), func(i, j int) { inRune[i], inRune[j] = inRune[j], inRune[i]