aboutsummaryrefslogtreecommitdiff
path: root/gotp.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-01-30 02:01:41 +0700
committerShulhan <ms@kilabit.info>2024-01-30 02:01:41 +0700
commit77ba620765a5682e05169be8b8740df925f612c8 (patch)
treee33f5273e5d124afb020040c4466f7a93c5cb3f7 /gotp.go
parenta6f27c3faea924a509915ab679511033893b773f (diff)
downloadgotp-77ba620765a5682e05169be8b8740df925f612c8.tar.xz
all: use [lib/crypto.LoadPrivateKeyInteractive]
The lib/crypto.LoadPrivateKeyInteractive provides a simple way to read passphrase from stdin that also support SSH_ASKPASS. While at it, add test for Cli with passphrase.
Diffstat (limited to 'gotp.go')
-rw-r--r--gotp.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/gotp.go b/gotp.go
index 52000a8..e268872 100644
--- a/gotp.go
+++ b/gotp.go
@@ -5,7 +5,9 @@
package gotp
import (
+ "io"
"strings"
+ "time"
"unicode"
)
@@ -30,6 +32,15 @@ const (
// Version define the latest version of this module and gotp CLI.
var Version = `0.4.0`
+// termrw define terminal for reading passphrase.
+// It is defined to mock parameter termrw in
+// [libcrypto.LoadPrivateKeyInteractive].
+var termrw io.ReadWriter
+
+// timeNow return the current time in UTC.
+// It is defined to mock current time for testing Generate.
+var timeNow = func() time.Time { return time.Now().UTC() }
+
// normalizeLabel convert non alpha number, hyphen, underscore, or period
// characters into `-`.
func normalizeLabel(in string) (out string) {