From 77ba620765a5682e05169be8b8740df925f612c8 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 30 Jan 2024 02:01:41 +0700 Subject: 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. --- cli.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'cli.go') 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 { -- cgit v1.3