diff options
Diffstat (limited to 'vendor/github.com/pquerna/otp/hotp/hotp.go')
-rw-r--r-- | vendor/github.com/pquerna/otp/hotp/hotp.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/vendor/github.com/pquerna/otp/hotp/hotp.go b/vendor/github.com/pquerna/otp/hotp/hotp.go index 5e99e2218e..7b94734045 100644 --- a/vendor/github.com/pquerna/otp/hotp/hotp.go +++ b/vendor/github.com/pquerna/otp/hotp/hotp.go @@ -19,6 +19,7 @@ package hotp import ( "github.com/pquerna/otp" + "io" "crypto/hmac" "crypto/rand" @@ -152,6 +153,8 @@ type GenerateOpts struct { Digits otp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm otp.Algorithm + // Reader to use for generating HOTP Key. + Rand io.Reader } var b32NoPadding = base32.StdEncoding.WithPadding(base32.NoPadding) @@ -175,6 +178,10 @@ func Generate(opts GenerateOpts) (*otp.Key, error) { opts.Digits = otp.DigitsSix } + if opts.Rand == nil { + opts.Rand = rand.Reader + } + // otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example v := url.Values{} @@ -182,7 +189,7 @@ func Generate(opts GenerateOpts) (*otp.Key, error) { v.Set("secret", b32NoPadding.EncodeToString(opts.Secret)) } else { secret := make([]byte, opts.SecretSize) - _, err := rand.Read(secret) + _, err := opts.Rand.Read(secret) if err != nil { return nil, err } |