Skip to content

Commit cf2cf1b

Browse files
committed
Make Validator public
1 parent 727c6fd commit cf2cf1b

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Parser struct {
1818
// Skip claims validation during token parsing.
1919
skipClaimsValidation bool
2020

21-
validator *validator
21+
validator *Validator
2222

2323
decodeStrict bool
2424

@@ -28,7 +28,7 @@ type Parser struct {
2828
// NewParser creates a new Parser with the specified options
2929
func NewParser(options ...ParserOption) *Parser {
3030
p := &Parser{
31-
validator: &validator{},
31+
validator: &Validator{},
3232
}
3333

3434
// Loop through our parsing options and apply them

validator.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ type ClaimsValidator interface {
2828
Validate() error
2929
}
3030

31-
// validator is the core of the new Validation API. It is automatically used by
31+
// Validator is the core of the new Validation API. It is automatically used by
3232
// a [Parser] during parsing and can be modified with various parser options.
3333
//
3434
// Note: This struct is intentionally not exported (yet) as we want to
3535
// internally finalize its API. In the future, we might make it publicly
3636
// available.
37-
type validator struct {
37+
type Validator struct {
3838
// leeway is an optional leeway that can be provided to account for clock skew.
3939
leeway time.Duration
4040

@@ -64,14 +64,14 @@ type validator struct {
6464

6565
// NewValidator can be used to create a stand-alone validator with the supplied
6666
// options. This validator can then be used to validate already parsed claims.
67-
func NewValidator(opts ...ParserOption) *validator {
67+
func NewValidator(opts ...ParserOption) *Validator {
6868
p := NewParser(opts...)
6969
return p.validator
7070
}
7171

7272
// Validate validates the given claims. It will also perform any custom
7373
// validation if claims implements the [ClaimsValidator] interface.
74-
func (v *validator) Validate(claims Claims) error {
74+
func (v *Validator) Validate(claims Claims) error {
7575
var (
7676
now time.Time
7777
errs []error = make([]error, 0, 6)
@@ -149,7 +149,7 @@ func (v *validator) Validate(claims Claims) error {
149149
//
150150
// Additionally, if any error occurs while retrieving the claim, e.g., when its
151151
// the wrong type, an ErrTokenUnverifiable error will be returned.
152-
func (v *validator) verifyExpiresAt(claims Claims, cmp time.Time, required bool) error {
152+
func (v *Validator) verifyExpiresAt(claims Claims, cmp time.Time, required bool) error {
153153
exp, err := claims.GetExpirationTime()
154154
if err != nil {
155155
return err
@@ -170,7 +170,7 @@ func (v *validator) verifyExpiresAt(claims Claims, cmp time.Time, required bool)
170170
//
171171
// Additionally, if any error occurs while retrieving the claim, e.g., when its
172172
// the wrong type, an ErrTokenUnverifiable error will be returned.
173-
func (v *validator) verifyIssuedAt(claims Claims, cmp time.Time, required bool) error {
173+
func (v *Validator) verifyIssuedAt(claims Claims, cmp time.Time, required bool) error {
174174
iat, err := claims.GetIssuedAt()
175175
if err != nil {
176176
return err
@@ -191,7 +191,7 @@ func (v *validator) verifyIssuedAt(claims Claims, cmp time.Time, required bool)
191191
//
192192
// Additionally, if any error occurs while retrieving the claim, e.g., when its
193193
// the wrong type, an ErrTokenUnverifiable error will be returned.
194-
func (v *validator) verifyNotBefore(claims Claims, cmp time.Time, required bool) error {
194+
func (v *Validator) verifyNotBefore(claims Claims, cmp time.Time, required bool) error {
195195
nbf, err := claims.GetNotBefore()
196196
if err != nil {
197197
return err
@@ -211,7 +211,7 @@ func (v *validator) verifyNotBefore(claims Claims, cmp time.Time, required bool)
211211
//
212212
// Additionally, if any error occurs while retrieving the claim, e.g., when its
213213
// the wrong type, an ErrTokenUnverifiable error will be returned.
214-
func (v *validator) verifyAudience(claims Claims, cmp string, required bool) error {
214+
func (v *Validator) verifyAudience(claims Claims, cmp string, required bool) error {
215215
aud, err := claims.GetAudience()
216216
if err != nil {
217217
return err
@@ -247,7 +247,7 @@ func (v *validator) verifyAudience(claims Claims, cmp string, required bool) err
247247
//
248248
// Additionally, if any error occurs while retrieving the claim, e.g., when its
249249
// the wrong type, an ErrTokenUnverifiable error will be returned.
250-
func (v *validator) verifyIssuer(claims Claims, cmp string, required bool) error {
250+
func (v *Validator) verifyIssuer(claims Claims, cmp string, required bool) error {
251251
iss, err := claims.GetIssuer()
252252
if err != nil {
253253
return err
@@ -267,7 +267,7 @@ func (v *validator) verifyIssuer(claims Claims, cmp string, required bool) error
267267
//
268268
// Additionally, if any error occurs while retrieving the claim, e.g., when its
269269
// the wrong type, an ErrTokenUnverifiable error will be returned.
270-
func (v *validator) verifySubject(claims Claims, cmp string, required bool) error {
270+
func (v *Validator) verifySubject(claims Claims, cmp string, required bool) error {
271271
sub, err := claims.GetSubject()
272272
if err != nil {
273273
return err

validator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (m MyCustomClaims) Validate() error {
2020
return nil
2121
}
2222

23-
func Test_validator_Validate(t *testing.T) {
23+
func Test_Validator_Validate(t *testing.T) {
2424
type fields struct {
2525
leeway time.Duration
2626
timeFunc func() time.Time
@@ -71,7 +71,7 @@ func Test_validator_Validate(t *testing.T) {
7171
}
7272
for _, tt := range tests {
7373
t.Run(tt.name, func(t *testing.T) {
74-
v := &validator{
74+
v := &Validator{
7575
leeway: tt.fields.leeway,
7676
timeFunc: tt.fields.timeFunc,
7777
verifyIat: tt.fields.verifyIat,
@@ -86,7 +86,7 @@ func Test_validator_Validate(t *testing.T) {
8686
}
8787
}
8888

89-
func Test_validator_verifyExpiresAt(t *testing.T) {
89+
func Test_Validator_verifyExpiresAt(t *testing.T) {
9090
type fields struct {
9191
leeway time.Duration
9292
timeFunc func() time.Time
@@ -117,7 +117,7 @@ func Test_validator_verifyExpiresAt(t *testing.T) {
117117
}
118118
for _, tt := range tests {
119119
t.Run(tt.name, func(t *testing.T) {
120-
v := &validator{
120+
v := &Validator{
121121
leeway: tt.fields.leeway,
122122
timeFunc: tt.fields.timeFunc,
123123
}
@@ -130,7 +130,7 @@ func Test_validator_verifyExpiresAt(t *testing.T) {
130130
}
131131
}
132132

133-
func Test_validator_verifyIssuer(t *testing.T) {
133+
func Test_Validator_verifyIssuer(t *testing.T) {
134134
type fields struct {
135135
expectedIss string
136136
}
@@ -160,7 +160,7 @@ func Test_validator_verifyIssuer(t *testing.T) {
160160
}
161161
for _, tt := range tests {
162162
t.Run(tt.name, func(t *testing.T) {
163-
v := &validator{
163+
v := &Validator{
164164
expectedIss: tt.fields.expectedIss,
165165
}
166166
err := v.verifyIssuer(tt.args.claims, tt.args.cmp, tt.args.required)
@@ -171,7 +171,7 @@ func Test_validator_verifyIssuer(t *testing.T) {
171171
}
172172
}
173173

174-
func Test_validator_verifySubject(t *testing.T) {
174+
func Test_Validator_verifySubject(t *testing.T) {
175175
type fields struct {
176176
expectedSub string
177177
}
@@ -201,7 +201,7 @@ func Test_validator_verifySubject(t *testing.T) {
201201
}
202202
for _, tt := range tests {
203203
t.Run(tt.name, func(t *testing.T) {
204-
v := &validator{
204+
v := &Validator{
205205
expectedSub: tt.fields.expectedSub,
206206
}
207207
err := v.verifySubject(tt.args.claims, tt.args.cmp, tt.args.required)
@@ -212,7 +212,7 @@ func Test_validator_verifySubject(t *testing.T) {
212212
}
213213
}
214214

215-
func Test_validator_verifyIssuedAt(t *testing.T) {
215+
func Test_Validator_verifyIssuedAt(t *testing.T) {
216216
type fields struct {
217217
leeway time.Duration
218218
timeFunc func() time.Time
@@ -248,7 +248,7 @@ func Test_validator_verifyIssuedAt(t *testing.T) {
248248
}
249249
for _, tt := range tests {
250250
t.Run(tt.name, func(t *testing.T) {
251-
v := &validator{
251+
v := &Validator{
252252
leeway: tt.fields.leeway,
253253
timeFunc: tt.fields.timeFunc,
254254
verifyIat: tt.fields.verifyIat,

0 commit comments

Comments
 (0)