Skip to content

Commit

Permalink
crypto/jwt: remove redundant len check in verify
Browse files Browse the repository at this point in the history
`len` returns 0 if the slice is nil. From the Go specification [1]:

  "1. For a nil slice, the number of iterations is 0."

Therefore, an additional `len(v) != 0` check for before the loop is
unnecessary.

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee committed Sep 27, 2023
1 parent effe01c commit 312adcb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions command/crypto/jwt/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,10 @@ func validateClaimsWithLeeway(ctx *cli.Context, c jose.Claims, e jose.Expected,
ers = append(ers, "invalid ID claim (jti)")
}

if len(e.Audience) != 0 {
for _, v := range e.Audience {
if !c.Audience.Contains(v) {
ers = append(ers, "invalid audience claim (aud)")
break
}
for _, v := range e.Audience {
if !c.Audience.Contains(v) {
ers = append(ers, "invalid audience claim (aud)")
break
}
}

Expand Down

0 comments on commit 312adcb

Please sign in to comment.