| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame] | 1 | package jwt |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | var ( |
| 9 | ErrInvalidKey = errors.New("key is invalid") |
| 10 | ErrInvalidKeyType = errors.New("key is of invalid type") |
| 11 | ErrHashUnavailable = errors.New("the requested hash function is unavailable") |
| 12 | ErrTokenMalformed = errors.New("token is malformed") |
| 13 | ErrTokenUnverifiable = errors.New("token is unverifiable") |
| 14 | ErrTokenSignatureInvalid = errors.New("token signature is invalid") |
| 15 | ErrTokenRequiredClaimMissing = errors.New("token is missing required claim") |
| 16 | ErrTokenInvalidAudience = errors.New("token has invalid audience") |
| 17 | ErrTokenExpired = errors.New("token is expired") |
| 18 | ErrTokenUsedBeforeIssued = errors.New("token used before issued") |
| 19 | ErrTokenInvalidIssuer = errors.New("token has invalid issuer") |
| 20 | ErrTokenInvalidSubject = errors.New("token has invalid subject") |
| 21 | ErrTokenNotValidYet = errors.New("token is not valid yet") |
| 22 | ErrTokenInvalidId = errors.New("token has invalid id") |
| 23 | ErrTokenInvalidClaims = errors.New("token has invalid claims") |
| 24 | ErrInvalidType = errors.New("invalid type for claim") |
| 25 | ) |
| 26 | |
| 27 | // joinedError is an error type that works similar to what [errors.Join] |
| 28 | // produces, with the exception that it has a nice error string; mainly its |
| 29 | // error messages are concatenated using a comma, rather than a newline. |
| 30 | type joinedError struct { |
| 31 | errs []error |
| 32 | } |
| 33 | |
| 34 | func (je joinedError) Error() string { |
| 35 | msg := []string{} |
| 36 | for _, err := range je.errs { |
| 37 | msg = append(msg, err.Error()) |
| 38 | } |
| 39 | |
| 40 | return strings.Join(msg, ", ") |
| 41 | } |
| 42 | |
| 43 | // joinErrors joins together multiple errors. Useful for scenarios where |
| 44 | // multiple errors next to each other occur, e.g., in claims validation. |
| 45 | func joinErrors(errs ...error) error { |
| 46 | return &joinedError{ |
| 47 | errs: errs, |
| 48 | } |
| 49 | } |