Refactor error formatting and update Go version in linter config

Reformatted error messages to use %w for improved error handling in "random.go", and updated the used Go version in the ".golangci.toml" file. Also, removed some unnecessary lines in "random_test.go" and improved the layout of an array in "koremutake.go".
This commit is contained in:
Winni Neessen 2024-03-12 21:23:15 +01:00
parent 8fef635664
commit 239501e83b
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
4 changed files with 8 additions and 8 deletions

View file

@ -3,14 +3,13 @@
# SPDX-License-Identifier: CC0-1.0
[run]
go = "1.20"
go = "1.22"
tests = true
skip-dirs = ["ui/"]
[linters]
enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder",
"errname", "errorlint", "gofmt", "gofumpt", "goimports"]
[linters-settings.goimports]
local-prefixes = "git.cgn.cleverbridge.com/infosec/vulnmon"
local-prefixes = "src.neessen.cloud/wneessen/apg-go"

View file

@ -6,7 +6,8 @@ package apg
// KoremutakeSyllables is a slightly modified Koremutake syllables list based on
// the mechanism described on https://shorl.com/koremutake.php
var KoremutakeSyllables = []string{"ba", "be", "bi", "bo", "bu", "by", "da", "de", "di",
var KoremutakeSyllables = []string{
"ba", "be", "bi", "bo", "bu", "by", "da", "de", "di",
"do", "du", "dy", "fe", "fi", "fo", "fu", "fy", "ga", "ge", "gi", "go", "gu",
"gy", "ha", "he", "hi", "ho", "hu", "hy", "ja", "je", "ji", "jo", "ju", "jy",
"ka", "ke", "ko", "ku", "ky", "la", "le", "li", "lo", "lu", "ly", "ma",
@ -23,4 +24,5 @@ var KoremutakeSyllables = []string{"ba", "be", "bi", "bo", "bu", "by", "da", "de
"col", "ful", "get", "low", "son", "tle", "day", "pen", "pre", "ten",
"tor", "ver", "ber", "can", "ple", "fer", "gen", "den", "mag", "sub", "sur",
"men", "min", "out", "tal", "but", "cit", "cle", "cov", "dif", "ern",
"eve", "hap", "ket", "nal", "sup", "ted", "tem", "tin", "tro", "tro"}
"eve", "hap", "ket", "nal", "sup", "ted", "tem", "tin", "tro", "tro",
}

View file

@ -318,7 +318,7 @@ func (g *Generator) generatePronounceable() (string, error) {
for int64(len(password)) < length {
randNum, err := g.RandNum(int64(characterSetLength))
if err != nil {
return "", fmt.Errorf("failed to generate a random number for Koremutake syllable generation: %s",
return "", fmt.Errorf("failed to generate a random number for Koremutake syllable generation: %w",
err)
}
nextSyllable := characterSet[randNum]
@ -326,7 +326,7 @@ func (g *Generator) generatePronounceable() (string, error) {
syllableLength := len(nextSyllable)
characterPosition, err := g.RandNum(int64(syllableLength))
if err != nil {
return "", fmt.Errorf("failed to generate a random number for Koremutake syllable generation: %s",
return "", fmt.Errorf("failed to generate a random number for Koremutake syllable generation: %w",
err)
}
randomChar := string(nextSyllable[characterPosition])

View file

@ -322,7 +322,6 @@ func TestGeneratePronounceable(t *testing.T) {
if foundSylables < 100 {
t.Errorf("generatePronounceable() failed, expected at least 1 sylable, got none")
}
}
func TestCheckMinimumRequirements(t *testing.T) {