From e19b029abb2014084bf19c5ccddf9415d362365e Mon Sep 17 00:00:00 2001
From: Lukas Braun <lukas.braun@fau.de>
Date: Sat, 4 Mar 2017 00:45:29 +0100
Subject: [PATCH] Use 8 digit OTPs

---
 goatherd.go      | 4 +++-
 goatherd_test.go | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/goatherd.go b/goatherd.go
index be9c2f1..cc22b23 100644
--- a/goatherd.go
+++ b/goatherd.go
@@ -19,6 +19,8 @@ import (
     "github.com/mattn/go-sqlite3"
 )
 
+const otpLen = 8
+
 // wrapper because time.Duration doesn't implement UnmarshalJSON
 type duration struct {
     time.Duration
@@ -174,7 +176,7 @@ func get_otp(db db_conn, name string) (*hotp.HOTP, error) {
     secret, count, err := get_user(db, name)
     if err != nil { return nil, err }
 
-    return hotp.NewHOTP(secret, count, 6), nil
+    return hotp.NewHOTP(secret, count, otpLen), nil
 }
 
 func transaction_failed(err error) bool {
diff --git a/goatherd_test.go b/goatherd_test.go
index 60627c2..c1ddc74 100644
--- a/goatherd_test.go
+++ b/goatherd_test.go
@@ -115,14 +115,14 @@ func check_offer_t(t *testing.T) {
         if ok { t.Fail() }
 
         t.Run("too_far_out", func(t *testing.T) {
-            ahead := hotp.NewHOTP(secret, count + cfg.Lookahead + 1, 6)
+            ahead := hotp.NewHOTP(secret, count + cfg.Lookahead + 1, otpLen)
             ok, err = check_offer(db, "mock", username, ahead.OTP())
             if ok { t.Fail() }
         })
     })
 
     t.Run("ok", func(t *testing.T) {
-        cur := hotp.NewHOTP(secret, count, 6)
+        cur := hotp.NewHOTP(secret, count, otpLen)
         ok, err := check_offer(db, "mock", username, cur.OTP())
         t_err_fatal(t, err)
         if !ok { t.Fail() }
@@ -136,7 +136,7 @@ func check_offer_t(t *testing.T) {
 
         t.Run("lookahead", func(t *testing.T) {
             ok, err := check_offer(db, "mock", username,
-                hotp.NewHOTP(secret, cur.Counter() + cfg.Lookahead, 6).OTP())
+                hotp.NewHOTP(secret, cur.Counter() + cfg.Lookahead, otpLen).OTP())
             t_err_fatal(t, err)
             if !ok { t.Fail() }
         })
-- 
GitLab