From 30e46a036b02c0f7a9a736ee6d44490dcdfe5b0c Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Fri, 28 Jun 2024 17:23:20 +0200 Subject: [PATCH] Change Period type to uint64 (#19) --- hotp.go | 2 +- otp.go | 4 ++-- totp.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hotp.go b/hotp.go index d4d6e63..38767a9 100644 --- a/hotp.go +++ b/hotp.go @@ -45,7 +45,7 @@ func NewHOTP(cfg HOTPConfig) (*HOTP, error) { func (h *HOTP) GenerateURL(account string, secret []byte) string { v := url.Values{} v.Set("algorithm", h.cfg.Algo.String()) - v.Set("digits", atoi(h.cfg.Digits)) + v.Set("digits", atoi(uint64(h.cfg.Digits))) v.Set("issuer", h.cfg.Issuer) v.Set("secret", b32Enc(secret)) diff --git a/otp.go b/otp.go index 03632b2..8668d8c 100644 --- a/otp.go +++ b/otp.go @@ -170,6 +170,6 @@ func b32Enc(src []byte) string { return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(src) } -func atoi(v uint) string { - return strconv.FormatUint(uint64(v), 10) +func atoi(v uint64) string { + return strconv.FormatUint(v, 10) } diff --git a/totp.go b/totp.go index f48da48..bfebd6b 100644 --- a/totp.go +++ b/totp.go @@ -16,7 +16,7 @@ type TOTPConfig struct { Algo Algorithm Digits uint Issuer string - Period uint + Period uint64 Skew uint } @@ -61,7 +61,7 @@ func NewTOTP(cfg TOTPConfig) (*TOTP, error) { func (t *TOTP) GenerateURL(account string, secret []byte) string { v := url.Values{} v.Set("algorithm", t.cfg.Algo.String()) - v.Set("digits", atoi(t.cfg.Digits)) + v.Set("digits", atoi(uint64(t.cfg.Digits))) v.Set("issuer", t.cfg.Issuer) v.Set("secret", b32Enc(secret)) v.Set("period", atoi(t.cfg.Period))