From 0c9db774ddd8435603a9685a062e1d530014e77e Mon Sep 17 00:00:00 2001 From: cyb3r4nt <104218001+cyb3r4nt@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:53:11 +0300 Subject: [PATCH] fix golangci-lint warnings --- provider/apple_pubkeys.go | 2 +- provider/apple_test.go | 8 ++++---- v2/provider/apple_pubkeys.go | 2 +- v2/provider/apple_test.go | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/provider/apple_pubkeys.go b/provider/apple_pubkeys.go index ce0ccde0..5c3563e5 100644 --- a/provider/apple_pubkeys.go +++ b/provider/apple_pubkeys.go @@ -151,7 +151,7 @@ type appleKeySet struct { // get return Apple public key with specific KeyID (kid) func (aks *appleKeySet) get(kid string) (keys *applePublicKey, err error) { - if aks.keys == nil || len(aks.keys) == 0 { + if len(aks.keys) == 0 { return nil, fmt.Errorf("failed to get key in appleKeySet, key set is nil or empty") } diff --git a/provider/apple_test.go b/provider/apple_test.go index f448ae77..51994a8d 100644 --- a/provider/apple_test.go +++ b/provider/apple_test.go @@ -5,11 +5,11 @@ import ( "crypto/rsa" "crypto/sha1" "encoding/base64" - "encoding/binary" "encoding/json" "fmt" "io" "log" + "math/big" "net/http" "net/http/cookiejar" "net/url" @@ -659,8 +659,8 @@ ODIRe1AuTyHceAbewn8b462yEWKARdpd9AjQW5SIVPfdsz5B6GlYQ5LdYKtznTuy n := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(publicKey.N.Bytes()) // convert exponent - eBuff := make([]byte, 4) - binary.LittleEndian.PutUint32(eBuff, uint32(publicKey.E)) + require.Positive(t, publicKey.E, "RSA exponent must be positive") + eBuff := big.NewInt(int64(publicKey.E)).Bytes() e := base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(eBuff) JWK := struct { @@ -670,7 +670,7 @@ ODIRe1AuTyHceAbewn8b462yEWKARdpd9AjQW5SIVPfdsz5B6GlYQ5LdYKtznTuy Kid string `json:"kid"` E string `json:"e"` N string `json:"n"` - }{Alg: "RS256", Kty: "RSA", Use: "sig", Kid: "112233", N: n, E: e[:4]} + }{Alg: "RS256", Kty: "RSA", Use: "sig", Kid: "112233", N: n, E: e} var buffJwk []byte buffJwk, err = json.Marshal(JWK) diff --git a/v2/provider/apple_pubkeys.go b/v2/provider/apple_pubkeys.go index c1975a2a..364503dd 100644 --- a/v2/provider/apple_pubkeys.go +++ b/v2/provider/apple_pubkeys.go @@ -151,7 +151,7 @@ type appleKeySet struct { // get return Apple public key with specific KeyID (kid) func (aks *appleKeySet) get(kid string) (keys *applePublicKey, err error) { - if aks.keys == nil || len(aks.keys) == 0 { + if len(aks.keys) == 0 { return nil, fmt.Errorf("failed to get key in appleKeySet, key set is nil or empty") } diff --git a/v2/provider/apple_test.go b/v2/provider/apple_test.go index 19d10892..4584777d 100644 --- a/v2/provider/apple_test.go +++ b/v2/provider/apple_test.go @@ -5,11 +5,11 @@ import ( "crypto/rsa" "crypto/sha1" "encoding/base64" - "encoding/binary" "encoding/json" "fmt" "io" "log" + "math/big" "net/http" "net/http/cookiejar" "net/url" @@ -659,8 +659,8 @@ ODIRe1AuTyHceAbewn8b462yEWKARdpd9AjQW5SIVPfdsz5B6GlYQ5LdYKtznTuy n := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(publicKey.N.Bytes()) // convert exponent - eBuff := make([]byte, 4) - binary.LittleEndian.PutUint32(eBuff, uint32(publicKey.E)) + require.Positive(t, publicKey.E, "RSA exponent must be positive") + eBuff := big.NewInt(int64(publicKey.E)).Bytes() e := base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(eBuff) JWK := struct { @@ -670,7 +670,7 @@ ODIRe1AuTyHceAbewn8b462yEWKARdpd9AjQW5SIVPfdsz5B6GlYQ5LdYKtznTuy Kid string `json:"kid"` E string `json:"e"` N string `json:"n"` - }{Alg: "RS256", Kty: "RSA", Use: "sig", Kid: "112233", N: n, E: e[:4]} + }{Alg: "RS256", Kty: "RSA", Use: "sig", Kid: "112233", N: n, E: e} var buffJwk []byte buffJwk, err = json.Marshal(JWK)