mirror of https://github.com/golang-jwt/jwt.git
chore: code cleanup (#10)
This commit is contained in:
parent
9e96e96514
commit
42625203e8
|
@ -35,18 +35,18 @@ func (c StandardClaims) Valid() error {
|
||||||
|
|
||||||
// The claims below are optional, by default, so if they are set to the
|
// 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.
|
// 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))
|
delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0))
|
||||||
vErr.Inner = fmt.Errorf("token is expired by %v", delta)
|
vErr.Inner = fmt.Errorf("token is expired by %v", delta)
|
||||||
vErr.Errors |= ValidationErrorExpired
|
vErr.Errors |= ValidationErrorExpired
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.VerifyIssuedAt(now, false) == false {
|
if !c.VerifyIssuedAt(now, false) {
|
||||||
vErr.Inner = fmt.Errorf("Token used before issued")
|
vErr.Inner = fmt.Errorf("Token used before issued")
|
||||||
vErr.Errors |= ValidationErrorIssuedAt
|
vErr.Errors |= ValidationErrorIssuedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.VerifyNotBefore(now, false) == false {
|
if !c.VerifyNotBefore(now, false) {
|
||||||
vErr.Inner = fmt.Errorf("token is not valid yet")
|
vErr.Inner = fmt.Errorf("token is not valid yet")
|
||||||
vErr.Errors |= ValidationErrorNotValidYet
|
vErr.Errors |= ValidationErrorNotValidYet
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func printJSON(j interface{}) error {
|
||||||
var out []byte
|
var out []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if *flagCompact == false {
|
if !*flagCompact {
|
||||||
out, err = json.MarshalIndent(j, "", " ")
|
out, err = json.MarshalIndent(j, "", " ")
|
||||||
} else {
|
} else {
|
||||||
out, err = json.Marshal(j)
|
out, err = json.Marshal(j)
|
||||||
|
|
6
ecdsa.go
6
ecdsa.go
|
@ -88,11 +88,11 @@ func (m *SigningMethodECDSA) Verify(signingString, signature string, key interfa
|
||||||
hasher.Write([]byte(signingString))
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
// Verify the signature
|
// 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
|
return nil
|
||||||
} else {
|
|
||||||
return ErrECDSAVerification
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ErrECDSAVerification
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements the Sign method from SigningMethod
|
// Implements the Sign method from SigningMethod
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
|
||||||
v, _ := exp.Int64()
|
v, _ := exp.Int64()
|
||||||
return verifyExp(v, cmp, req)
|
return verifyExp(v, cmp, req)
|
||||||
}
|
}
|
||||||
return req == false
|
return !req
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compares the iat claim against cmp.
|
// Compares the iat claim against cmp.
|
||||||
|
@ -40,7 +40,7 @@ func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool {
|
||||||
v, _ := iat.Int64()
|
v, _ := iat.Int64()
|
||||||
return verifyIat(v, cmp, req)
|
return verifyIat(v, cmp, req)
|
||||||
}
|
}
|
||||||
return req == false
|
return !req
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compares the iss claim against cmp.
|
// Compares the iss claim against cmp.
|
||||||
|
@ -60,7 +60,7 @@ func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool {
|
||||||
v, _ := nbf.Int64()
|
v, _ := nbf.Int64()
|
||||||
return verifyNbf(v, cmp, req)
|
return verifyNbf(v, cmp, req)
|
||||||
}
|
}
|
||||||
return req == false
|
return !req
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validates time based claims "exp, iat, nbf".
|
// Validates time based claims "exp, iat, nbf".
|
||||||
|
@ -71,17 +71,17 @@ func (m MapClaims) Valid() error {
|
||||||
vErr := new(ValidationError)
|
vErr := new(ValidationError)
|
||||||
now := TimeFunc().Unix()
|
now := TimeFunc().Unix()
|
||||||
|
|
||||||
if m.VerifyExpiresAt(now, false) == false {
|
if !m.VerifyExpiresAt(now, false) {
|
||||||
vErr.Inner = errors.New("Token is expired")
|
vErr.Inner = errors.New("Token is expired")
|
||||||
vErr.Errors |= ValidationErrorExpired
|
vErr.Errors |= ValidationErrorExpired
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.VerifyIssuedAt(now, false) == false {
|
if !m.VerifyIssuedAt(now, false) {
|
||||||
vErr.Inner = errors.New("Token used before issued")
|
vErr.Inner = errors.New("Token used before issued")
|
||||||
vErr.Errors |= ValidationErrorIssuedAt
|
vErr.Errors |= ValidationErrorIssuedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.VerifyNotBefore(now, false) == false {
|
if !m.VerifyNotBefore(now, false) {
|
||||||
vErr.Inner = errors.New("Token is not valid yet")
|
vErr.Inner = errors.New("Token is not valid yet")
|
||||||
vErr.Errors |= ValidationErrorNotValidYet
|
vErr.Errors |= ValidationErrorNotValidYet
|
||||||
}
|
}
|
||||||
|
|
2
token.go
2
token.go
|
@ -65,7 +65,7 @@ func (t *Token) SignedString(key interface{}) (string, error) {
|
||||||
func (t *Token) SigningString() (string, error) {
|
func (t *Token) SigningString() (string, error) {
|
||||||
var err error
|
var err error
|
||||||
parts := make([]string, 2)
|
parts := make([]string, 2)
|
||||||
for i, _ := range parts {
|
for i := range parts {
|
||||||
var jsonValue []byte
|
var jsonValue []byte
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if jsonValue, err = json.Marshal(t.Header); err != nil {
|
if jsonValue, err = json.Marshal(t.Header); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue