Add password generation UI profile workflow

This commit is contained in:
Joe Julian
2026-03-29 11:21:10 -07:00
parent bd9674a1f5
commit 16dc1de3c8
8 changed files with 186 additions and 77 deletions
+27
View File
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"slices"
"strings"
)
@@ -16,6 +17,7 @@ const (
)
var ErrImpossibleProfile = errors.New("impossible password profile")
var ErrUnknownProfile = errors.New("unknown password profile")
type Profile struct {
Name string
@@ -61,6 +63,31 @@ func DefaultProfiles() map[string]Profile {
}
}
func DefaultProfileNames() []string {
return ProfileNames(DefaultProfiles())
}
func LookupProfile(name string, profiles map[string]Profile) (Profile, error) {
profile, ok := profiles[strings.TrimSpace(name)]
if !ok {
return Profile{}, fmt.Errorf("%w %q", ErrUnknownProfile, strings.TrimSpace(name))
}
return profile, nil
}
func LookupDefaultProfile(name string) (Profile, error) {
return LookupProfile(name, DefaultProfiles())
}
func ProfileNames(profiles map[string]Profile) []string {
names := make([]string, 0, len(profiles))
for name := range profiles {
names = append(names, name)
}
slices.Sort(names)
return names
}
func Generate(profile Profile) (string, error) {
if err := validateProfile(profile); err != nil {
return "", err