File: oath_test.go

package info (click to toggle)
golang-github-gokyle-twofactor 1.0.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 120 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 636 bytes parent folder | download | duplicates (2)
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
package twofactor

import (
	"fmt"
	"testing"
)

var sha1Hmac = []byte{
	0x1f, 0x86, 0x98, 0x69, 0x0e,
	0x02, 0xca, 0x16, 0x61, 0x85,
	0x50, 0xef, 0x7f, 0x19, 0xda,
	0x8e, 0x94, 0x5b, 0x55, 0x5a,
}

var truncExpect int64 = 0x50ef7f19

// This test runs through the truncation example given in the RFC.
func TestTruncate(t *testing.T) {
	if result := truncate(sha1Hmac); result != truncExpect {
		fmt.Printf("hotp: expected truncate -> %d, saw %d\n",
			truncExpect, result)
		t.FailNow()
	}

	sha1Hmac[19]++
	if result := truncate(sha1Hmac); result == truncExpect {
		fmt.Println("hotp: expected truncation to fail")
		t.FailNow()
	}
}