1package twofactor
2
3import (
4	"fmt"
5	"testing"
6)
7
8var sha1Hmac = []byte{
9	0x1f, 0x86, 0x98, 0x69, 0x0e,
10	0x02, 0xca, 0x16, 0x61, 0x85,
11	0x50, 0xef, 0x7f, 0x19, 0xda,
12	0x8e, 0x94, 0x5b, 0x55, 0x5a,
13}
14
15var truncExpect int64 = 0x50ef7f19
16
17// This test runs through the truncation example given in the RFC.
18func TestTruncate(t *testing.T) {
19	if result := truncate(sha1Hmac); result != truncExpect {
20		fmt.Printf("hotp: expected truncate -> %d, saw %d\n",
21			truncExpect, result)
22		t.FailNow()
23	}
24
25	sha1Hmac[19]++
26	if result := truncate(sha1Hmac); result == truncExpect {
27		fmt.Println("hotp: expected truncation to fail")
28		t.FailNow()
29	}
30}
31