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.
| paddy@96 | 1 package auth |
| paddy@96 | 2 |
| paddy@96 | 3 import ( |
| paddy@96 | 4 "errors" |
| paddy@96 | 5 "html/template" |
| paddy@101 | 6 "log" |
| paddy@96 | 7 ) |
| paddy@96 | 8 |
| paddy@96 | 9 var ( |
| paddy@96 | 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. |
| paddy@96 | 11 ErrInvalidLoginURI = errors.New("invalid login URI") |
| paddy@96 | 12 ) |
| paddy@96 | 13 |
| paddy@96 | 14 // Config holds the configuration values necessary to run a server. A Config |
| paddy@96 | 15 // instance is the only way to instantiate a Context variable. |
| paddy@96 | 16 type Config struct { |
| paddy@96 | 17 ClientStore clientStore |
| paddy@96 | 18 AuthCodeStore authorizationCodeStore |
| paddy@96 | 19 ProfileStore profileStore |
| paddy@96 | 20 TokenStore tokenStore |
| paddy@96 | 21 SessionStore sessionStore |
| paddy@96 | 22 Template *template.Template |
| paddy@96 | 23 LoginURI string |
| paddy@96 | 24 iterations int |
| paddy@96 | 25 } |
| paddy@101 | 26 |
| paddy@101 | 27 func (c *Config) Init() error { |
| paddy@101 | 28 scheme, ok := passphraseSchemes[CurPassphraseScheme] |
| paddy@101 | 29 if !ok { |
| paddy@101 | 30 return ErrInvalidPassphraseScheme |
| paddy@101 | 31 } |
| paddy@101 | 32 var err error |
| paddy@101 | 33 c.iterations, err = scheme.calculateIterations() |
| paddy@101 | 34 if err != nil { |
| paddy@101 | 35 return err |
| paddy@101 | 36 } |
| paddy@101 | 37 log.Printf("Generating passphrases with %d iterations...\n", c.iterations) |
| paddy@101 | 38 return nil |
| paddy@101 | 39 } |