Skip to content

Commit 821eee0

Browse files
committed
verify: add context to algorithm mismatch error
1 parent 37314c1 commit 821eee0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

verify.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package jwt
22

33
import (
44
"bytes"
5-
"errors"
5+
6+
"github.com/gbrlsnchs/jwt/v3/internal"
67
)
78

89
// ErrAlgValidation indicates an incoming JWT's "alg" field mismatches the Validator's.
9-
var ErrAlgValidation = errors.New(`"alg" field mismatch`)
10+
var ErrAlgValidation = internal.NewError(`invalid "alg" field`)
1011

1112
// VerifyOption is a functional option for verifying.
1213
type VerifyOption func(*RawToken) error
@@ -54,7 +55,7 @@ func Verify(token []byte, alg Algorithm, payload interface{}, opts ...VerifyOpti
5455
// in the JOSE header is the same used by the algorithm.
5556
func ValidateHeader(rt *RawToken) error {
5657
if rt.alg.Name() != rt.hd.Algorithm {
57-
return ErrAlgValidation
58+
return internal.Errorf("jwt: %q: %w", rt.hd.Algorithm, ErrAlgValidation)
5859
}
5960
return nil
6061
}

0 commit comments

Comments
 (0)