From 42625203e874984c7a00f726e12cefea86652011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 28 May 2021 01:26:21 +0200 Subject: [PATCH] chore: code cleanup (#10) --- claims.go | 6 +++--- cmd/jwt/app.go | 2 +- ecdsa.go | 6 +++--- map_claims.go | 12 ++++++------ token.go | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/claims.go b/claims.go index f0228f0..1133fd4 100644 --- a/claims.go +++ b/claims.go @@ -35,18 +35,18 @@ func (c StandardClaims) Valid() error { // The claims below are optional, by default, so if they are set to the // default value in Go, let's not fail the verification for them. - if c.VerifyExpiresAt(now, false) == false { + if !c.VerifyExpiresAt(now, false) { delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0)) vErr.Inner = fmt.Errorf("token is expired by %v", delta) vErr.Errors |= ValidationErrorExpired } - if c.VerifyIssuedAt(now, false) == false { + if !c.VerifyIssuedAt(now, false) { vErr.Inner = fmt.Errorf("Token used before issued") vErr.Errors |= ValidationErrorIssuedAt } - if c.VerifyNotBefore(now, false) == false { + if !c.VerifyNotBefore(now, false) { vErr.Inner = fmt.Errorf("token is not valid yet") vErr.Errors |= ValidationErrorNotValidYet } diff --git a/cmd/jwt/app.go b/cmd/jwt/app.go index cdf2500..2807574 100644 --- a/cmd/jwt/app.go +++ b/cmd/jwt/app.go @@ -98,7 +98,7 @@ func printJSON(j interface{}) error { var out []byte var err error - if *flagCompact == false { + if !*flagCompact { out, err = json.MarshalIndent(j, "", " ") } else { out, err = json.Marshal(j) diff --git a/ecdsa.go b/ecdsa.go index f977381..d310af1 100644 --- a/ecdsa.go +++ b/ecdsa.go @@ -88,11 +88,11 @@ func (m *SigningMethodECDSA) Verify(signingString, signature string, key interfa hasher.Write([]byte(signingString)) // Verify the signature - if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus == true { + if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus { return nil - } else { - return ErrECDSAVerification } + + return ErrECDSAVerification } // Implements the Sign method from SigningMethod diff --git a/map_claims.go b/map_claims.go index 291213c..e1d6f3f 100644 --- a/map_claims.go +++ b/map_claims.go @@ -27,7 +27,7 @@ func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool { v, _ := exp.Int64() return verifyExp(v, cmp, req) } - return req == false + return !req } // Compares the iat claim against cmp. @@ -40,7 +40,7 @@ func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool { v, _ := iat.Int64() return verifyIat(v, cmp, req) } - return req == false + return !req } // Compares the iss claim against cmp. @@ -60,7 +60,7 @@ func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool { v, _ := nbf.Int64() return verifyNbf(v, cmp, req) } - return req == false + return !req } // Validates time based claims "exp, iat, nbf". @@ -71,17 +71,17 @@ func (m MapClaims) Valid() error { vErr := new(ValidationError) now := TimeFunc().Unix() - if m.VerifyExpiresAt(now, false) == false { + if !m.VerifyExpiresAt(now, false) { vErr.Inner = errors.New("Token is expired") vErr.Errors |= ValidationErrorExpired } - if m.VerifyIssuedAt(now, false) == false { + if !m.VerifyIssuedAt(now, false) { vErr.Inner = errors.New("Token used before issued") vErr.Errors |= ValidationErrorIssuedAt } - if m.VerifyNotBefore(now, false) == false { + if !m.VerifyNotBefore(now, false) { vErr.Inner = errors.New("Token is not valid yet") vErr.Errors |= ValidationErrorNotValidYet } diff --git a/token.go b/token.go index d637e08..99868d2 100644 --- a/token.go +++ b/token.go @@ -65,7 +65,7 @@ func (t *Token) SignedString(key interface{}) (string, error) { func (t *Token) SigningString() (string, error) { var err error parts := make([]string, 2) - for i, _ := range parts { + for i := range parts { var jsonValue []byte if i == 0 { if jsonValue, err = json.Marshal(t.Header); err != nil {