| 1 |
package gotp |
| 2 |
|
| 3 |
|
| 4 |
type HOTP struct { |
| 5 |
OTP |
| 6 |
} |
| 7 |
|
| 8 |
func NewHOTP(secret string, digits int, hasher *Hasher) *HOTP { |
| 9 |
otp := NewOTP(secret, digits, hasher) |
| 10 |
return &HOTP{OTP: otp} |
| 11 |
|
| 12 |
} |
| 13 |
|
| 14 |
func NewDefaultHOTP(secret string) *HOTP { |
| 15 |
return NewHOTP(secret, 6, nil) |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
func (h *HOTP) At(count int) string { |
| 20 |
return h.generateOTP(count) |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
func (h *HOTP) Verify(otp string, count int) bool { |
| 31 |
return otp == h.At(count) |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
func (h *HOTP) ProvisioningUri(accountName, issuerName string, initialCount int) string { |
| 49 |
return BuildUri( |
| 50 |
OtpTypeHotp, |
| 51 |
h.secret, |
| 52 |
accountName, |
| 53 |
issuerName, |
| 54 |
h.hasher.HashName, |
| 55 |
initialCount, |
| 56 |
h.digits, |
| 57 |
0) |
| 58 |
} |