Debian Codegraph @

hotp.go

raw symbols SCIP
1 package gotp
2
3 // HMAC-based OTP counters.
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 // Generates the OTP for the given count.
19 func (h *HOTP) At(count int) string {
20 return h.generateOTP(count)
21 }
22
23 /*
24 Verify OTP.
25
26 params:
27 otp: the OTP to check against
28 count: the OTP HMAC counter
29 */
30 func (h *HOTP) Verify(otp string, count int) bool {
31 return otp == h.At(count)
32 }
33
34 /*
35 Returns the provisioning URI for the OTP.
36 This can then be encoded in a QR Code and used to provision an OTP app like Google Authenticator.
37
38 See also:
39 https://github.com/google/google-authenticator/wiki/Key-Uri-Format
40
41 params:
42 accountName: name of the account
43 issuerName: the name of the OTP issuer; this will be the organization title of the OTP entry in Authenticator
44 initialCount: starting HMAC counter value
45
46 returns: provisioning URI
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 }