Skip to content

Commit 562a1d7

Browse files
committed
Minor lint fixes
- Remove redundant nil check in NewHMACSHA256Signer - Remove unused keyID field in TestNewRSASigner1 - Replace interface{} with any for modern Go idiom - Add lint ignore directive for intentional reEncodeQPs naming - Add error handling in test - Add explanatory comments for intentional lowercase header keys
1 parent a023926 commit 562a1d7

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

crypto.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Signer struct {
3434
// NewHMACSHA256Signer returns a new Signer structure. Key must be at least 64 bytes long.
3535
// Config may be nil for a default configuration.
3636
func NewHMACSHA256Signer(key []byte, config *SignConfig, fields Fields) (*Signer, error) {
37-
if key == nil || len(key) < 64 {
37+
if len(key) < 64 {
3838
return nil, fmt.Errorf("key must be at least 64 bytes long")
3939
}
4040
if config == nil {

crypto_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestNewHMACSHA256Signer(t *testing.T) {
7171

7272
func TestSigner_sign(t *testing.T) {
7373
type fields struct {
74-
key interface{}
74+
key any
7575
alg string
7676
}
7777
type args struct {
@@ -210,7 +210,6 @@ func makeRSAPrivateKey() *rsa.PrivateKey {
210210
}
211211
func TestNewRSASigner1(t *testing.T) {
212212
type args struct {
213-
keyID string
214213
key *rsa.PrivateKey
215214
config *SignConfig
216215
fields Fields
@@ -256,7 +255,7 @@ func TestNewRSASigner1(t *testing.T) {
256255
func TestNewJWSVerifier(t *testing.T) {
257256
type args struct {
258257
alg jwa.SignatureAlgorithm
259-
key interface{}
258+
key any
260259
keyID string
261260
config *VerifyConfig
262261
fields Fields
@@ -418,7 +417,7 @@ func TestMessageForeignSignerV3(t *testing.T) {
418417
func TestNewJWSVerifierV3(t *testing.T) {
419418
type args struct {
420419
alg jwav3.SignatureAlgorithm
421-
key interface{}
420+
key any
422421
config *VerifyConfig
423422
fields Fields
424423
}

httpparse.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func parseRequest(req *http.Request, withTrailers bool) (*parsedMessage, error)
4141
return parseMessage(msg, withTrailers)
4242
}
4343

44+
//lint:ignore ST1003 QPs is intentional abbreviation for Query Parameters
4445
func reEncodeQPs(values url.Values) url.Values {
4546
escaped := url.Values{}
4647
for key, v := range values { // Re-escape query parameters, both names and values

signatures.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,17 @@ func ResponseSignatureNames(res *http.Response, withTrailers bool) ([]string, er
464464
}
465465

466466
func messageSignatureNames(parsedMessage *parsedMessage, withTrailers bool) ([]string, error) {
467-
//lint:ignore SA1008 the Header type expects canonicalized names, tough
467+
// Note: parsedMessage.headers intentionally uses lowercase keys (see httpparse.go)
468+
// Linter warning about non-canonical key is expected and can be ignored
468469
signatureField := parsedMessage.headers["signature"]
469470
dict, err := httpsfv.UnmarshalDictionary(signatureField)
470471
if err != nil {
471472
return nil, fmt.Errorf("cannot parse signature field: %w", err)
472473
}
473474
names := dict.Names()
474475
if withTrailers {
475-
//lint:ignore SA1008 the Header type expects canonicalized names, tough
476+
// Note: parsedMessage.trailers intentionally uses lowercase keys (see httpparse.go)
477+
// Linter warning about non-canonical key is expected and can be ignored
476478
signatureField := parsedMessage.trailers["signature"]
477479
dict, err := httpsfv.UnmarshalDictionary(signatureField)
478480
if err != nil {

signatures_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,7 @@ func TestMessageRequestBindingSignedResponse17(t *testing.T) {
30623062

30633063
res := readResponse(httpres10)
30643064
msg, err := NewMessage(NewMessageConfig().WithResponse(res, req))
3065+
assert.NoError(t, err, "cannot create message")
30653066
pubKey2, err := parseECPublicKeyFromPemStr(p256PubKey2)
30663067
assert.NoError(t, err, "read pub key")
30673068
fields2 := *NewFields().AddHeaders("@status", "content-digest", "content-type").

0 commit comments

Comments
 (0)