Initial import.

Basic HOTP functionality.
This commit is contained in:
Kyle Isom
2013-12-18 21:48:14 -07:00
commit dbbd5116b5
5 changed files with 340 additions and 0 deletions

40
hotp.go Normal file
View File

@@ -0,0 +1,40 @@
package twofactor
import (
"crypto"
"crypto/sha1"
)
type HOTP struct {
*oath
}
func (otp *HOTP) Type() Type {
return OATH_HOTP
}
func NewHOTP(key []byte, counter uint64, digits int) *HOTP {
return &HOTP{
oath: &oath{
key: key,
counter: counter,
size: digits,
hash: sha1.New,
algo: crypto.SHA1,
},
}
}
func (otp *HOTP) OTP() string {
code := otp.oath.OTP(otp.counter)
otp.counter++
return code
}
func (otp *HOTP) URL(label string) string {
return otp.oath.URL(otp.Type(), label)
}
func (otp *HOTP) SetProvider(provider string) {
otp.provider = provider
}