From 459e9f880f7088fbe3534e10ebefaff6d733e2dc Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 23 Apr 2014 16:54:16 -0700 Subject: [PATCH] Add function to build Google TOTPs from secret --- totp.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/totp.go b/totp.go index 2727a41..3904920 100644 --- a/totp.go +++ b/totp.go @@ -99,6 +99,14 @@ func GenerateGoogleTOTP() *TOTP { return NewTOTP(key, 0, 30, 6, crypto.SHA1) } +func NewGoogleTOTP(secret string) (*TOTP, error) { + key, err := base32.StdEncoding.DecodeString(secret) + if err != nil { + return nil, err + } + return NewTOTP(key, 0, 30, 6, crypto.SHA1), nil +} + func totpFromURL(u *url.URL) (*TOTP, string, error) { label := u.Path[1:] v := u.Query()