-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotp_test.go
66 lines (55 loc) · 1.49 KB
/
hotp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package otp_test
import (
"crypto"
_ "crypto/sha1"
_ "crypto/sha256"
_ "crypto/sha512"
"encoding/hex"
"testing"
otp "github.com/chardon55/otp2go"
)
func TestHTOP1(t *testing.T) {
input := "3132333435363738393031323334353637383930"
counter := 1
expected := "94287082"
hexBytes, err := hex.DecodeString(input)
if err != nil {
panic(err)
}
hotp := otp.NewHOTP(hexBytes, crypto.SHA1)
hotp.SetCounter(uint64(counter))
result := hotp.GenerateString8()
if expected != result {
t.Errorf("Not matched. Expected: %s; Actual: %s", expected, result)
}
}
func TestHTOP2(t *testing.T) {
input := "3132333435363738393031323334353637383930313233343536373839303132"
counter := 0x23523ED
expected := "67062674"
hexBytes, err := hex.DecodeString(input)
if err != nil {
panic(err)
}
hotp := otp.NewHOTP(hexBytes, crypto.SHA256)
hotp.SetCounter(uint64(counter))
result := hotp.GenerateString8()
if expected != result {
t.Errorf("Not matched. Expected: %s; Actual: %s", expected, result)
}
}
func TestHTOP3(t *testing.T) {
input := "31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334"
counter := 0x23523EC
expected := "25091201"
hexBytes, err := hex.DecodeString(input)
if err != nil {
panic(err)
}
hotp := otp.NewHOTP(hexBytes, crypto.SHA512)
hotp.SetCounter(uint64(counter))
result := hotp.GenerateString8()
if expected != result {
t.Errorf("Not matched. Expected: %s; Actual: %s", expected, result)
}
}