Skip to content

Commit 75740f1

Browse files
authored
replaced interface{} to any (#445)
* replaced interface{} to any in KeyFunc * replaced interface{} to its alias any * updated comments and MIGRATION_GUIDE.md file * replaced []any to []interface{} in test name because it is not a comment
1 parent 048854f commit 75740f1

28 files changed

+98
-98
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ stored in base64 encoded form, which was redundant with the information in the
155155
type Token struct {
156156
Raw string // Raw contains the raw token
157157
Method SigningMethod // Method is the signing method used or to be used
158-
Header map[string]interface{} // Header is the first segment of the token in decoded form
158+
Header map[string]any // Header is the first segment of the token in decoded form
159159
Claims Claims // Claims is the second segment of the token in decoded form
160160
Signature []byte // Signature is the third segment of the token in decoded form
161161
Valid bool // Valid specifies if the token is valid

cmd/jwt/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func loadData(p string) ([]byte, error) {
9999
}
100100

101101
// Print a json object in accordance with the prophecy (or the command line options)
102-
func printJSON(j interface{}) error {
102+
func printJSON(j any) error {
103103
var out []byte
104104
var err error
105105

@@ -132,7 +132,7 @@ func verifyToken() error {
132132
}
133133

134134
// Parse the token. Load the key from command line option
135-
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) (interface{}, error) {
135+
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) (any, error) {
136136
if isNone() {
137137
return jwt.UnsafeAllowNoneSignatureType, nil
138138
}
@@ -196,7 +196,7 @@ func signToken() error {
196196
}
197197

198198
// get the key
199-
var key interface{}
199+
var key any
200200
if isNone() {
201201
key = jwt.UnsafeAllowNoneSignatureType
202202
} else {

ecdsa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (m *SigningMethodECDSA) Alg() string {
5555

5656
// Verify implements token verification for the SigningMethod.
5757
// For this verify method, key must be an ecdsa.PublicKey struct
58-
func (m *SigningMethodECDSA) Verify(signingString string, sig []byte, key interface{}) error {
58+
func (m *SigningMethodECDSA) Verify(signingString string, sig []byte, key any) error {
5959
// Get the key
6060
var ecdsaKey *ecdsa.PublicKey
6161
switch k := key.(type) {
@@ -89,7 +89,7 @@ func (m *SigningMethodECDSA) Verify(signingString string, sig []byte, key interf
8989

9090
// Sign implements token signing for the SigningMethod.
9191
// For this signing method, key must be an ecdsa.PrivateKey struct
92-
func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) ([]byte, error) {
92+
func (m *SigningMethodECDSA) Sign(signingString string, key any) ([]byte, error) {
9393
// Get the key
9494
var ecdsaKey *ecdsa.PrivateKey
9595
switch k := key.(type) {

ecdsa_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,39 @@ var ecdsaTestData = []struct {
1515
keys map[string]string
1616
tokenString string
1717
alg string
18-
claims map[string]interface{}
18+
claims map[string]any
1919
valid bool
2020
}{
2121
{
2222
"Basic ES256",
2323
map[string]string{"private": "test/ec256-private.pem", "public": "test/ec256-public.pem"},
2424
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJmb28iOiJiYXIifQ.feG39E-bn8HXAKhzDZq7yEAPWYDhZlwTn3sePJnU9VrGMmwdXAIEyoOnrjreYlVM_Z4N13eK9-TmMTWyfKJtHQ",
2525
"ES256",
26-
map[string]interface{}{"foo": "bar"},
26+
map[string]any{"foo": "bar"},
2727
true,
2828
},
2929
{
3030
"Basic ES384",
3131
map[string]string{"private": "test/ec384-private.pem", "public": "test/ec384-public.pem"},
3232
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzM4NCJ9.eyJmb28iOiJiYXIifQ.ngAfKMbJUh0WWubSIYe5GMsA-aHNKwFbJk_wq3lq23aPp8H2anb1rRILIzVR0gUf4a8WzDtrzmiikuPWyCS6CN4-PwdgTk-5nehC7JXqlaBZU05p3toM3nWCwm_LXcld",
3333
"ES384",
34-
map[string]interface{}{"foo": "bar"},
34+
map[string]any{"foo": "bar"},
3535
true,
3636
},
3737
{
3838
"Basic ES512",
3939
map[string]string{"private": "test/ec512-private.pem", "public": "test/ec512-public.pem"},
4040
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzUxMiJ9.eyJmb28iOiJiYXIifQ.AAU0TvGQOcdg2OvrwY73NHKgfk26UDekh9Prz-L_iWuTBIBqOFCWwwLsRiHB1JOddfKAls5do1W0jR_F30JpVd-6AJeTjGKA4C1A1H6gIKwRY0o_tFDIydZCl_lMBMeG5VNFAjO86-WCSKwc3hqaGkq1MugPRq_qrF9AVbuEB4JPLyL5",
4141
"ES512",
42-
map[string]interface{}{"foo": "bar"},
42+
map[string]any{"foo": "bar"},
4343
true,
4444
},
4545
{
4646
"basic ES256 invalid: foo => bar",
4747
map[string]string{"private": "test/ec256-private.pem", "public": "test/ec256-public.pem"},
4848
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.MEQCIHoSJnmGlPaVQDqacx_2XlXEhhqtWceVopjomc2PJLtdAiAUTeGPoNYxZw0z8mgOnnIcjoxRuNDVZvybRZF3wR1l8W",
4949
"ES256",
50-
map[string]interface{}{"foo": "bar"},
50+
map[string]any{"foo": "bar"},
5151
false,
5252
},
5353
}

ecdsa_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
2323
}
2424

2525
// Parse the key
26-
var parsedKey interface{}
26+
var parsedKey any
2727
if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil {
2828
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
2929
return nil, err
@@ -50,7 +50,7 @@ func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) {
5050
}
5151

5252
// Parse the key
53-
var parsedKey interface{}
53+
var parsedKey any
5454
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
5555
if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
5656
parsedKey = cert.PublicKey

ed25519.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (m *SigningMethodEd25519) Alg() string {
3333

3434
// Verify implements token verification for the SigningMethod.
3535
// For this verify method, key must be an ed25519.PublicKey
36-
func (m *SigningMethodEd25519) Verify(signingString string, sig []byte, key interface{}) error {
36+
func (m *SigningMethodEd25519) Verify(signingString string, sig []byte, key any) error {
3737
var ed25519Key ed25519.PublicKey
3838
var ok bool
3939

@@ -55,7 +55,7 @@ func (m *SigningMethodEd25519) Verify(signingString string, sig []byte, key inte
5555

5656
// Sign implements token signing for the SigningMethod.
5757
// For this signing method, key must be an ed25519.PrivateKey
58-
func (m *SigningMethodEd25519) Sign(signingString string, key interface{}) ([]byte, error) {
58+
func (m *SigningMethodEd25519) Sign(signingString string, key any) ([]byte, error) {
5959
var ed25519Key crypto.Signer
6060
var ok bool
6161

ed25519_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ var ed25519TestData = []struct {
1313
keys map[string]string
1414
tokenString string
1515
alg string
16-
claims map[string]interface{}
16+
claims map[string]any
1717
valid bool
1818
}{
1919
{
2020
"Basic Ed25519",
2121
map[string]string{"private": "test/ed25519-private.pem", "public": "test/ed25519-public.pem"},
2222
"eyJhbGciOiJFRDI1NTE5IiwidHlwIjoiSldUIn0.eyJmb28iOiJiYXIifQ.ESuVzZq1cECrt9Od_gLPVG-_6uRP_8Nq-ajx6CtmlDqRJZqdejro2ilkqaQgSL-siE_3JMTUW7UwAorLaTyFCw",
2323
"EdDSA",
24-
map[string]interface{}{"foo": "bar"},
24+
map[string]any{"foo": "bar"},
2525
true,
2626
},
2727
{
2828
"Basic Ed25519",
2929
map[string]string{"private": "test/ed25519-private.pem", "public": "test/ed25519-public.pem"},
3030
"eyJhbGciOiJFRDI1NTE5IiwidHlwIjoiSldUIn0.eyJmb28iOiJiYXoifQ.ESuVzZq1cECrt9Od_gLPVG-_6uRP_8Nq-ajx6CtmlDqRJZqdejro2ilkqaQgSL-siE_3JMTUW7UwAorLaTyFCw",
3131
"EdDSA",
32-
map[string]interface{}{"foo": "bar"},
32+
map[string]any{"foo": "bar"},
3333
false,
3434
},
3535
}

ed25519_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error) {
2424
}
2525

2626
// Parse the key
27-
var parsedKey interface{}
27+
var parsedKey any
2828
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
2929
return nil, err
3030
}
@@ -49,7 +49,7 @@ func ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error) {
4949
}
5050

5151
// Parse the key
52-
var parsedKey interface{}
52+
var parsedKey any
5353
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
5454
return nil, err
5555
}

example_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func ExampleParseWithClaims_customClaimsType() {
8484
jwt.RegisteredClaims
8585
}
8686

87-
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
87+
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (any, error) {
8888
return []byte("AllYourBase"), nil
8989
})
9090
if err != nil {
@@ -108,7 +108,7 @@ func ExampleParseWithClaims_validationOptions() {
108108
jwt.RegisteredClaims
109109
}
110110

111-
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
111+
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (any, error) {
112112
return []byte("AllYourBase"), nil
113113
}, jwt.WithLeeway(5*time.Second))
114114
if err != nil {
@@ -147,7 +147,7 @@ func (m MyCustomClaims) Validate() error {
147147
func ExampleParseWithClaims_customValidation() {
148148
tokenString := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpc3MiOiJ0ZXN0IiwiYXVkIjoic2luZ2xlIn0.QAWg1vGvnqRuCFTMcPkjZljXHh8U3L_qUjszOtQbeaA"
149149

150-
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
150+
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (any, error) {
151151
return []byte("AllYourBase"), nil
152152
}, jwt.WithLeeway(5*time.Second))
153153
if err != nil {
@@ -166,7 +166,7 @@ func ExampleParse_errorChecking() {
166166
// Token from another example. This token is expired
167167
var tokenString = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJleHAiOjE1MDAwLCJpc3MiOiJ0ZXN0In0.HE7fK0xOQwFEr4WDgRWj4teRPZ6i3GLwD5YCm6Pwu_c"
168168

169-
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
169+
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) {
170170
return []byte("AllYourBase"), nil
171171
})
172172

hmac.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (m *SigningMethodHMAC) Alg() string {
5555
// about this, and why we intentionally are not supporting string as a key can
5656
// be found on our usage guide
5757
// https://golang-jwt.github.io/jwt/usage/signing_methods/#signing-methods-and-key-types.
58-
func (m *SigningMethodHMAC) Verify(signingString string, sig []byte, key interface{}) error {
58+
func (m *SigningMethodHMAC) Verify(signingString string, sig []byte, key any) error {
5959
// Verify the key is the right type
6060
keyBytes, ok := key.([]byte)
6161
if !ok {
@@ -88,7 +88,7 @@ func (m *SigningMethodHMAC) Verify(signingString string, sig []byte, key interfa
8888
// cryptographically random source, e.g. crypto/rand. Additional information
8989
// about this, and why we intentionally are not supporting string as a key can
9090
// be found on our usage guide https://golang-jwt.github.io/jwt/usage/signing_methods/.
91-
func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) ([]byte, error) {
91+
func (m *SigningMethodHMAC) Sign(signingString string, key any) ([]byte, error) {
9292
if keyBytes, ok := key.([]byte); ok {
9393
if !m.Hash.Available() {
9494
return nil, ErrHashUnavailable

0 commit comments

Comments
 (0)