parseNumericDate tries to parse a key in the map claims type as a number date. This will succeed, if the underlying type is either a [float64] or a [json.Number]. Otherwise, nil will be returned.
(key string)
| 43 | // date. This will succeed, if the underlying type is either a [float64] or a |
| 44 | // [json.Number]. Otherwise, nil will be returned. |
| 45 | func (m MapClaims) parseNumericDate(key string) (*NumericDate, error) { |
| 46 | v, ok := m[key] |
| 47 | if !ok { |
| 48 | return nil, nil |
| 49 | } |
| 50 | |
| 51 | switch exp := v.(type) { |
| 52 | case float64: |
| 53 | if exp == 0 { |
| 54 | return nil, nil |
| 55 | } |
| 56 | |
| 57 | return newNumericDateFromSeconds(exp), nil |
| 58 | case json.Number: |
| 59 | v, _ := exp.Float64() |
| 60 | |
| 61 | return newNumericDateFromSeconds(v), nil |
| 62 | } |
| 63 | |
| 64 | return nil, newError(fmt.Sprintf("%s is invalid", key), ErrInvalidType) |
| 65 | } |
| 66 | |
| 67 | // parseClaimsString tries to parse a key in the map claims type as a |
| 68 | // [ClaimsStrings] type, which can either be a string or an array of string. |
no test coverage detected