go-spectre/site_password.go

32 lines
717 B
Go

package spectre
import "strings"
func site(userKey []byte, scoper Scoper, siteName string, opts ...SiteOption) string {
siteOpts := &options{
template: "",
counter: 1,
scope: Authentication,
}
for _, opt := range opts {
opt(siteOpts)
}
if siteOpts.template == "" {
siteOpts.template = siteOpts.scope.DefaultTemplate()
}
siteKey := siteKey(userKey, scoper, siteName, siteOpts.counter, siteOpts.scope)
templateSet := templates[siteOpts.template]
template := templateSet[int(siteKey[0])%len(templateSet)]
var out strings.Builder
for idx, b := range template {
chars := characters[string(b)]
char := chars[int(siteKey[idx+1])%len(chars)]
out.WriteByte(char)
}
return out.String()
}