auth

Paddy 2014-12-14 Parent:e57a57a944c4 Child:267483f168b5

101:e98d19699ee9 Go to Latest

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.

History
     1.1 --- a/config.go	Sun Dec 14 12:10:57 2014 -0500
     1.2 +++ b/config.go	Sun Dec 14 16:23:10 2014 -0500
     1.3 @@ -3,6 +3,7 @@
     1.4  import (
     1.5  	"errors"
     1.6  	"html/template"
     1.7 +	"log"
     1.8  )
     1.9  
    1.10  var (
    1.11 @@ -22,3 +23,17 @@
    1.12  	LoginURI      string
    1.13  	iterations    int
    1.14  }
    1.15 +
    1.16 +func (c *Config) Init() error {
    1.17 +	scheme, ok := passphraseSchemes[CurPassphraseScheme]
    1.18 +	if !ok {
    1.19 +		return ErrInvalidPassphraseScheme
    1.20 +	}
    1.21 +	var err error
    1.22 +	c.iterations, err = scheme.calculateIterations()
    1.23 +	if err != nil {
    1.24 +		return err
    1.25 +	}
    1.26 +	log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
    1.27 +	return nil
    1.28 +}