aboutsummaryrefslogtreecommitdiff
path: root/cli.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 /cli.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 'cli.go')
-rw-r--r--cli.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/cli.go b/cli.go
index c07dcad..e3b6d77 100644
--- a/cli.go
+++ b/cli.go
@@ -110,7 +110,7 @@ func (cli *Cli) Generate(label string, n int) (listOtp []string, err error) {
proto = totp.New(cryptoHash, issuer.Digits, issuer.TimeStep)
- listOtp, err = proto.GenerateN(secret, n)
+ listOtp, err = proto.GenerateNWithTime(timeNow(), secret, n)
if err != nil {
return nil, fmt.Errorf(`%s: %w`, logp, err)
}
@@ -193,14 +193,13 @@ func (cli *Cli) List() (labels []string) {
// Remove a TOTP configuration by its label.
func (cli *Cli) Remove(label string) (err error) {
- var (
- logp = `Remove`
-
- ok bool
- )
+ var logp = `Remove`
+ label = strings.TrimSpace(label)
label = strings.ToLower(label)
+ var ok bool
+
_, ok = cli.cfg.Issuers[label]
if !ok {
return fmt.Errorf(`%s: %q not exist`, logp, label)
@@ -286,12 +285,14 @@ func (cli *Cli) Rename(label, newLabel string) (err error) {
ok bool
)
+ label = strings.TrimSpace(label)
label = strings.ToLower(label)
rawValue, ok = cli.cfg.Issuers[label]
if !ok {
return fmt.Errorf(`%s: %q not exist`, logp, label)
}
+ newLabel = strings.TrimSpace(newLabel)
newLabel = strings.ToLower(newLabel)
_, ok = cli.cfg.Issuers[newLabel]
if ok {