Skip to content

Commit

Permalink
Merge branch 'golang-jwt:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
washboard-cpu committed May 28, 2021
2 parents 243b6a0 + 4262520 commit f697a60
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/jwt/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions map_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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".
Expand All @@ -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
}
Expand Down

0 comments on commit f697a60

Please sign in to comment.