MCPcopy
hub / github.com/golang-jwt/jwt / parseNumericDate

Method parseNumericDate

map_claims.go:45–65  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43// date. This will succeed, if the underlying type is either a [float64] or a
44// [json.Number]. Otherwise, nil will be returned.
45func (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.

Callers 3

GetExpirationTimeMethod · 0.95
GetNotBeforeMethod · 0.95
GetIssuedAtMethod · 0.95

Calls 2

newErrorFunction · 0.85

Tested by

no test coverage detected