From 312adcb0f8c13512ea98937b555c5d7462ab0606 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Thu, 28 Sep 2023 01:12:16 +0800 Subject: [PATCH] crypto/jwt: remove redundant `len` check in verify `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 --- command/crypto/jwt/verify.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/command/crypto/jwt/verify.go b/command/crypto/jwt/verify.go index 3ed710808..7f0e00674 100644 --- a/command/crypto/jwt/verify.go +++ b/command/crypto/jwt/verify.go @@ -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 } }