diff --git a/parser.go b/parser.go index 253f9e7..16135bd 100644 --- a/parser.go +++ b/parser.go @@ -7,9 +7,6 @@ import ( "strings" ) -// DefaultValidator is the default validator that is used, if no custom validator is supplied in a Parser. -var DefaultValidator = NewValidator() - type Parser struct { // If populated, only these methods will be considered valid. // diff --git a/validator.go b/validator.go index aab6846..faaea87 100644 --- a/validator.go +++ b/validator.go @@ -6,7 +6,10 @@ import ( "time" ) -// Validator is the core of the new Validation API. It is +// Validator is the core of the new Validation API. It can either be used to +// modify the validation used during parsing with the [WithValidator] parser +// option or used standalone to validate an already parsed [Claim]. It can be +// further customized with a range of specified [ValidatorOption]s. type Validator struct { // leeway is an optional leeway that can be provided to account for clock skew. leeway time.Duration @@ -28,6 +31,8 @@ type Validator struct { } type customValidationType interface { + // CustomValidation can be implemented by a user-specific claim to support + // additional validation steps in addition to the regular validation. CustomValidation() error } @@ -177,8 +182,8 @@ func verifyIat(iat *time.Time, now time.Time, required bool, skew time.Duration) return !required } - t := (*iat).Add(-skew) - return now.After(t) || now.Equal(t) + t := iat.Add(-skew) + return !now.Before(t) } func verifyNbf(nbf *time.Time, now time.Time, required bool, skew time.Duration) bool { @@ -186,8 +191,8 @@ func verifyNbf(nbf *time.Time, now time.Time, required bool, skew time.Duration) return !required } - t := (*nbf).Add(-skew) - return now.After(t) || now.Equal(t) + t := nbf.Add(-skew) + return !now.Before(t) } func verifyIss(iss string, cmp string, required bool) bool {