github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/appengine/login/googlesignin/jwt-go/errors.go (about) 1 package jwt 2 3 import ( 4 "errors" 5 ) 6 7 // Error constants 8 var ( 9 ErrInvalidKey = errors.New("key is invalid or of invalid type") 10 ErrHashUnavailable = errors.New("the requested hash function is unavailable") 11 ErrNoTokenInRequest = errors.New("no token present in request") 12 ) 13 14 // The errors that might occur when parsing and validating a token 15 const ( 16 ValidationErrorMalformed uint32 = 1 << iota // Token is malformed 17 ValidationErrorUnverifiable // Token could not be verified because of signing problems 18 ValidationErrorSignatureInvalid // Signature validation failed 19 ValidationErrorExpired // Exp validation failed 20 ValidationErrorNotValidYet // NBF validation failed 21 ) 22 23 // The error from Parse if token is not valid 24 type ValidationError struct { 25 err string 26 Errors uint32 // bitfield. see ValidationError... constants 27 } 28 29 // Validation error is an error type 30 func (e ValidationError) Error() string { 31 if e.err == "" { 32 return "token is invalid" 33 } 34 return e.err 35 } 36 37 // No errors 38 func (e *ValidationError) valid() bool { 39 if e.Errors > 0 { 40 return false 41 } 42 return true 43 }