Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warnings from golangci-lint #34

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions totp/example_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package totp_test

import (
"encoding/hex"
"fmt"
"log"
"strconv"

"github.com/KEINOS/go-totp/totp"
)
Expand Down Expand Up @@ -175,6 +177,7 @@ gX7ff3VlT4sCakCjQH69ZQxTbzs=
// Function: GenerateKeyURI
// ----------------------------------------------------------------------------

//nolint:goconst // origin appears many times but leave it as is as example.
func ExampleGenerateKeyURI() {
origin := "otpauth://totp/Example.com:[email protected]?algorithm=SHA1&" +
"digits=12&issuer=Example.com&period=60&secret=QF7N673VMVHYWATKICRUA7V5MUGFG3Z3"
Expand Down Expand Up @@ -224,7 +227,7 @@ func ExampleKey() {
// AccountName: [email protected]
}

//nolint:funlen // length is 62 lines long but leave it as is due to embedded example
//nolint:funlen // length is 62 lines long but leave it as is due to embedded example.
func ExampleKey_QRCode() {
origin := "otpauth://totp/Example.com:[email protected]?algorithm=SHA1&" +
"digits=6&issuer=Example.com&period=30&secret=QF7N673VMVHYWATKICRUA7V5MUGFG3Z3"
Expand All @@ -247,7 +250,7 @@ func ExampleKey_QRCode() {
log.Fatal(err)
}

actual := fmt.Sprintf("%x", pngImage)
actual := hex.EncodeToString(pngImage)
expect := `89504e470d0a1a0a0000000d4948445200000064000000641000000000051` +
`916cb0000040549444154789ce45ced6edb400c9387bcff2b67180a2f324d5272ff` +
`95d59f35f7691f4f12a9047bbddf1561afaae3d0dde76bf631bdeddfdffd5f370fd` +
Expand Down Expand Up @@ -495,7 +498,7 @@ func ExampleStrToUint() {
fmt.Printf("uint1: %v, type: %T\n", uint1, uint1)

// Note that number that overflows the uint will return 0.
str2 := fmt.Sprintf("%d", uint64(0xFFFFFFFF+1))
str2 := strconv.FormatUint(uint64(0xFFFFFFFF+1), 10)
uint2 := totp.StrToUint(str2)

fmt.Printf("uint2: %v, type: %T\n", uint2, uint2)
Expand Down
10 changes: 5 additions & 5 deletions totp/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package totp

import (
"encoding/pem"
"fmt"
"net/url"
"strconv"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -181,9 +181,9 @@ func (k *Key) PEM() (string, error) {
"Algorithm": k.Options.Algorithm.String(),
"Digits": k.Options.Digits.String(),
"Issuer": k.Options.Issuer,
"Period": fmt.Sprintf("%d", k.Options.Period),
"Secret Size": fmt.Sprintf("%d", k.Options.SecretSize),
"Skew": fmt.Sprintf("%d", k.Options.Skew),
"Period": strconv.FormatUint(uint64(k.Options.Period), 10),
"Secret Size": strconv.FormatUint(uint64(k.Options.SecretSize), 10),
"Skew": strconv.FormatUint(uint64(k.Options.Skew), 10),
},
Bytes: k.Secret.Bytes(),
})
Expand Down Expand Up @@ -221,7 +221,7 @@ func (k *Key) URI() string {
queryVal.Set("algorithm", k.Options.Algorithm.String())
queryVal.Set("digits", k.Options.Digits.String())
queryVal.Set("secret", k.Secret.Base32())
queryVal.Set("period", fmt.Sprintf("%d", k.Options.Period))
queryVal.Set("period", strconv.FormatUint(uint64(k.Options.Period), 10))

//nolint:exhaustruct // other fields are left blank on purpose
urlOut := url.URL{
Expand Down
1 change: 1 addition & 0 deletions totp/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func TestGenerateKeyURI_error_msg(t *testing.T) {
return nil, errors.New("forced error")
}

//nolint:goconst // many occurrences but leave it
key2, err := GenerateKeyURI("otpauth://totp/Example.com:[email protected]?algorithm=SHA1&" +
"digits=12&issuer=Example.com&period=60&secret=QF7N673VMVHYWATKICRUA7V5MUGFG3Z3")

Expand Down
Loading