Skip to content

Commit

Permalink
feat!: Update GetWordList to return []string instead of []byte
Browse files Browse the repository at this point in the history
  • Loading branch information
eljamo committed Dec 5, 2023
1 parent ea9286f commit ad54316
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 21 deletions.
6 changes: 3 additions & 3 deletions asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"strings"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

//go:embed preset/* word_list/*
Expand Down Expand Up @@ -68,7 +68,7 @@ func LoadJSONFile(filePath string) (string, error) {
return loadFileData(filePath, os.ReadFile)
}

func GetWordList(key string) ([]byte, error) {
func GetWordList(key string) ([]string, error) {
fileName, ok := keyToFile(key, config.WordListKey)
if !ok {
return nil, fmt.Errorf("invalid word list key '%s'", key)
Expand All @@ -80,7 +80,7 @@ func GetWordList(key string) ([]byte, error) {
return nil, fmt.Errorf("failed to read embedded text file '%s': %w", filePath, err)
}

return data, nil
return strings.Split(string(data), "\n"), nil
}

func GetJSONPreset(key string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/eljamo/libpass/v2
module github.com/eljamo/libpass/v3

go 1.21.4

Expand Down
4 changes: 2 additions & 2 deletions service/padding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"unicode/utf8"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v2/internal/stringcheck"
"github.com/eljamo/libpass/v3/config"
"github.com/eljamo/libpass/v3/internal/stringcheck"
)

type PaddingService interface {
Expand Down
2 changes: 1 addition & 1 deletion service/padding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

func TestNewPaddingService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion service/password_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"sync"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

type PasswordGeneratorService interface {
Expand Down
2 changes: 1 addition & 1 deletion service/password_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

type mockTransformerService struct{}
Expand Down
4 changes: 2 additions & 2 deletions service/separator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package service
import (
"errors"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v2/internal/stringcheck"
"github.com/eljamo/libpass/v3/config"
"github.com/eljamo/libpass/v3/internal/stringcheck"
)

type SeparatorService interface {
Expand Down
2 changes: 1 addition & 1 deletion service/separator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"slices"
"testing"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

func TestNewSeparatorService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion service/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"unicode"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down
2 changes: 1 addition & 1 deletion service/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"testing"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

func TestNewTransformerService(t *testing.T) {
Expand Down
9 changes: 3 additions & 6 deletions service/word_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package service
import (
"errors"
"fmt"
"strings"

"github.com/eljamo/libpass/v2/asset"
"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/asset"
"github.com/eljamo/libpass/v3/config"
)

type WordListService interface {
Expand Down Expand Up @@ -46,10 +45,8 @@ func getWordList(wordList string, wordMinLength int, wordMaxLength int) ([]strin
return nil, err
}

aw := strings.Split(string(wl), "\n")
var fw []string

for _, word := range aw {
for _, word := range wl {
if len(word) >= wordMinLength && len(word) <= wordMaxLength {
fw = append(fw, string(word))
}
Expand Down
2 changes: 1 addition & 1 deletion service/word_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package service
import (
"testing"

"github.com/eljamo/libpass/v2/config"
"github.com/eljamo/libpass/v3/config"
)

func TestNewWordListService(t *testing.T) {
Expand Down

0 comments on commit ad54316

Please sign in to comment.