package ui import ( "fmt" "git.wxccs.org/iceking2nd/winauth-go/internal/authenticator" "git.wxccs.org/iceking2nd/winauth-go/internal/config" ) // entryFromAuthenticator builds a serializable config.Entry from an // in-memory authenticator plus its display name. The vendor string is // derived from the authenticator's Name() (which already returns // "google" / "microsoft" / "okta" / "hotp" / "battlenet" / "steam"). func entryFromAuthenticator(name string, a authenticator.Authenticator, hotkey string) config.Entry { return config.Entry{ Name: name, Vendor: a.Name(), SecretRaw: a.SecretData(), Hotkey: hotkey, } } // buildAuthenticator is the reverse of entryFromAuthenticator: it picks // the right concrete type based on vendor, then asks it to parse the // stored secret blob. func buildAuthenticator(e config.Entry) (authenticator.Authenticator, error) { const fn = "internal.ui.buildAuthenticator" var a authenticator.Authenticator switch e.Vendor { case "google", "": a = authenticator.NewGoogleAuthenticator() case "microsoft": a = authenticator.NewMicrosoftAuthenticator() case "okta": a = authenticator.NewOktaVerifyAuthenticator() case "hotp": a = authenticator.NewHOTPAuthenticator() case "battlenet": a = authenticator.NewBattleNetAuthenticator() case "steam": a = authenticator.NewSteamAuthenticator() default: return nil, fmt.Errorf("%s: unknown vendor %q", fn, e.Vendor) } if err := a.SetSecretData(e.SecretRaw); err != nil { return nil, fmt.Errorf("%s: decode entry %q: %w", fn, e.Name, err) } return a, nil }