auth
auth/config.go
Add config init function to calculate passphrase iterations. Create a config.Init function that should be called on program startup. It calculates the number of iterations the passphrase encryption should use.
1 package auth
3 import (
4 "errors"
5 "html/template"
6 "log"
7 )
9 var (
10 // ErrInvalidLoginURI is returned when a Context is instantiated with a Config object that specifies a LoginURI that can't be parsed as a URL.
11 ErrInvalidLoginURI = errors.New("invalid login URI")
12 )
14 // Config holds the configuration values necessary to run a server. A Config
15 // instance is the only way to instantiate a Context variable.
16 type Config struct {
17 ClientStore clientStore
18 AuthCodeStore authorizationCodeStore
19 ProfileStore profileStore
20 TokenStore tokenStore
21 SessionStore sessionStore
22 Template *template.Template
23 LoginURI string
24 iterations int
25 }
27 func (c *Config) Init() error {
28 scheme, ok := passphraseSchemes[CurPassphraseScheme]
29 if !ok {
30 return ErrInvalidPassphraseScheme
31 }
32 var err error
33 c.iterations, err = scheme.calculateIterations()
34 if err != nil {
35 return err
36 }
37 log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
38 return nil
39 }