Home

go-spectre @c33188090acd8fd23b310533ecb497d14cd0f66c - refs - log -
-
https://git.jolheiser.com/go-spectre.git
Go implementation for spectre/masterpassword
go-spectre / site_password.go
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()
}