aboutsummaryrefslogtreecommitdiff
path: root/cli.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-08-06 23:12:42 +0700
committerShulhan <ms@kilabit.info>2022-08-06 23:12:42 +0700
commit25809666ff0050b10e786714ae97c0c00df48918 (patch)
treefb839733811c5440e7c56dd625ad606977114784 /cli.go
parent69b2de6d86cb8c8caa57c0d4f452ca91a387beda (diff)
downloadgotp-25809666ff0050b10e786714ae97c0c00df48918.tar.xz
all: fix base32 decoding on secret
The base32 decoding should be without padding otherwise it will return an error (for some base32 string): illegal base32 data at input byte 48
Diffstat (limited to 'cli.go')
-rw-r--r--cli.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/cli.go b/cli.go
index ed655ee..f22e626 100644
--- a/cli.go
+++ b/cli.go
@@ -150,12 +150,12 @@ func (cli *Cli) Add(issuer *Issuer) (err error) {
return nil
}
-//
// Generate n number of OTP from given issuer name.
-//
func (cli *Cli) Generate(label string, n int) (listOtp []string, err error) {
var (
- logp = "Generate"
+ logp = `Generate`
+ b32Enc = base32.StdEncoding.WithPadding(base32.NoPadding)
+
cryptoHash totp.CryptoHash
)
@@ -164,7 +164,7 @@ func (cli *Cli) Generate(label string, n int) (listOtp []string, err error) {
return nil, fmt.Errorf("%s: %w", logp, err)
}
- secret, err := base32.StdEncoding.DecodeString(issuer.Secret)
+ secret, err := b32Enc.DecodeString(issuer.Secret)
if err != nil {
return nil, fmt.Errorf("%s: secret is not a valid base32 encoding: %w", logp, err)
}