From 868cf39632ac54c1b2795589f0fe9bd8acf38b08 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Tue, 26 Sep 2023 19:54:48 +0200 Subject: [PATCH] pkg/oidc: Replace `interface{}` with `any` Signed-off-by: Thomas Hipp --- pkg/oidc/error.go | 2 +- pkg/oidc/keyset.go | 6 +++--- pkg/oidc/regression_test.go | 6 +++--- pkg/oidc/token.go | 6 +++--- pkg/oidc/token_request.go | 4 ++-- pkg/oidc/token_test.go | 12 ++++++------ pkg/oidc/types.go | 6 +++--- pkg/oidc/verifier.go | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pkg/oidc/error.go b/pkg/oidc/error.go index 79acecd..9e265b3 100644 --- a/pkg/oidc/error.go +++ b/pkg/oidc/error.go @@ -151,7 +151,7 @@ func (e *Error) WithParent(err error) *Error { return e } -func (e *Error) WithDescription(desc string, args ...interface{}) *Error { +func (e *Error) WithDescription(desc string, args ...any) *Error { e.Description = fmt.Sprintf(desc, args...) return e } diff --git a/pkg/oidc/keyset.go b/pkg/oidc/keyset.go index c6e865b..7b766a5 100644 --- a/pkg/oidc/keyset.go +++ b/pkg/oidc/keyset.go @@ -46,8 +46,8 @@ func GetKeyIDAndAlg(jws *jose.JSONWebSignature) (string, string) { // // will return false none or multiple match // -//deprecated: use FindMatchingKey which will return an error (more specific) instead of just a bool -//moved implementation already to FindMatchingKey +// deprecated: use FindMatchingKey which will return an error (more specific) instead of just a bool +// moved implementation already to FindMatchingKey func FindKey(keyID, use, expectedAlg string, keys ...jose.JSONWebKey) (jose.JSONWebKey, bool) { key, err := FindMatchingKey(keyID, use, expectedAlg, keys...) return key, err == nil @@ -91,7 +91,7 @@ func FindMatchingKey(keyID, use, expectedAlg string, keys ...jose.JSONWebKey) (k return key, ErrKeyNone } -func algToKeyType(key interface{}, alg string) bool { +func algToKeyType(key any, alg string) bool { switch alg[0] { case 'R', 'P': _, ok := key.(*rsa.PublicKey) diff --git a/pkg/oidc/regression_test.go b/pkg/oidc/regression_test.go index 5d33bb6..9cb3ff9 100644 --- a/pkg/oidc/regression_test.go +++ b/pkg/oidc/regression_test.go @@ -17,7 +17,7 @@ const dataDir = "regression_data" // jsonFilename builds a filename for the regression testdata. // dataDir/.json -func jsonFilename(obj interface{}) string { +func jsonFilename(obj any) string { name := fmt.Sprintf("%T.json", obj) return path.Join( dataDir, @@ -25,13 +25,13 @@ func jsonFilename(obj interface{}) string { ) } -func encodeJSON(t *testing.T, w io.Writer, obj interface{}) { +func encodeJSON(t *testing.T, w io.Writer, obj any) { enc := json.NewEncoder(w) enc.SetIndent("", "\t") require.NoError(t, enc.Encode(obj)) } -var regressionData = []interface{}{ +var regressionData = []any{ accessTokenData, idTokenData, introspectionResponseData, diff --git a/pkg/oidc/token.go b/pkg/oidc/token.go index 5283eb5..36d546c 100644 --- a/pkg/oidc/token.go +++ b/pkg/oidc/token.go @@ -222,7 +222,7 @@ type JWTProfileAssertionClaims struct { Expiration Time `json:"exp"` IssuedAt Time `json:"iat"` - Claims map[string]interface{} `json:"-"` + Claims map[string]any `json:"-"` } type jpaAlias JWTProfileAssertionClaims @@ -262,7 +262,7 @@ func JWTProfileDelegatedSubject(sub string) func(*JWTProfileAssertionClaims) { } } -func JWTProfileCustomClaim(key string, value interface{}) func(*JWTProfileAssertionClaims) { +func JWTProfileCustomClaim(key string, value any) func(*JWTProfileAssertionClaims) { return func(j *JWTProfileAssertionClaims) { j.Claims[key] = value } @@ -292,7 +292,7 @@ func NewJWTProfileAssertion(userID, keyID string, audience []string, key []byte, IssuedAt: FromTime(time.Now().UTC()), Expiration: FromTime(time.Now().Add(1 * time.Hour).UTC()), Audience: audience, - Claims: make(map[string]interface{}), + Claims: make(map[string]any), } for _, opt := range opts { diff --git a/pkg/oidc/token_request.go b/pkg/oidc/token_request.go index 5c5cf20..07c4ca0 100644 --- a/pkg/oidc/token_request.go +++ b/pkg/oidc/token_request.go @@ -130,7 +130,7 @@ type JWTTokenRequest struct { IssuedAt Time `json:"iat"` ExpiresAt Time `json:"exp"` - private map[string]interface{} + private map[string]any } func (j *JWTTokenRequest) MarshalJSON() ([]byte, error) { @@ -171,7 +171,7 @@ func (j *JWTTokenRequest) UnmarshalJSON(data []byte) error { return nil } -func (j *JWTTokenRequest) GetCustomClaim(key string) interface{} { +func (j *JWTTokenRequest) GetCustomClaim(key string) any { return j.private[key] } diff --git a/pkg/oidc/token_test.go b/pkg/oidc/token_test.go index ef1e77f..f3ea8d2 100644 --- a/pkg/oidc/token_test.go +++ b/pkg/oidc/token_test.go @@ -29,7 +29,7 @@ var ( accessTokenData = &AccessTokenClaims{ TokenClaims: tokenClaimsData, Scopes: []string{"email", "phone"}, - Claims: map[string]interface{}{ + Claims: map[string]any{ "foo": "bar", }, } @@ -43,7 +43,7 @@ var ( UserInfoEmail: userInfoData.UserInfoEmail, UserInfoPhone: userInfoData.UserInfoPhone, Address: userInfoData.Address, - Claims: map[string]interface{}{ + Claims: map[string]any{ "foo": "bar", }, } @@ -64,7 +64,7 @@ var ( UserInfoEmail: userInfoData.UserInfoEmail, UserInfoPhone: userInfoData.UserInfoPhone, Address: userInfoData.Address, - Claims: map[string]interface{}{ + Claims: map[string]any{ "foo": "bar", }, } @@ -102,7 +102,7 @@ var ( PostalCode: "666-666", Country: "Moon", }, - Claims: map[string]interface{}{ + Claims: map[string]any{ "foo": "bar", }, } @@ -114,7 +114,7 @@ var ( Audience: Audience{"foo", "bar"}, Expiration: 12345, IssuedAt: 12000, - Claims: map[string]interface{}{ + Claims: map[string]any{ "foo": "bar", }, } @@ -181,7 +181,7 @@ func TestIDTokenClaims_SetUserInfo(t *testing.T) { UserInfoEmail: userInfoData.UserInfoEmail, UserInfoPhone: userInfoData.UserInfoPhone, Address: userInfoData.Address, - Claims: map[string]interface{}{ + Claims: map[string]any{ "foo": "bar", }, } diff --git a/pkg/oidc/types.go b/pkg/oidc/types.go index 23367ef..6ab7469 100644 --- a/pkg/oidc/types.go +++ b/pkg/oidc/types.go @@ -17,13 +17,13 @@ import ( type Audience []string func (a *Audience) UnmarshalJSON(text []byte) error { - var i interface{} + var i any err := json.Unmarshal(text, &i) if err != nil { return err } switch aud := i.(type) { - case []interface{}: + case []any: *a = make([]string, len(aud)) for i, audience := range aud { (*a)[i] = audience.(string) @@ -177,7 +177,7 @@ func (s *SpaceDelimitedArray) UnmarshalJSON(data []byte) error { return nil } -func (s *SpaceDelimitedArray) Scan(src interface{}) error { +func (s *SpaceDelimitedArray) Scan(src any) error { if src == nil { *s = nil return nil diff --git a/pkg/oidc/verifier.go b/pkg/oidc/verifier.go index c4ee95e..1af1ebb 100644 --- a/pkg/oidc/verifier.go +++ b/pkg/oidc/verifier.go @@ -85,7 +85,7 @@ func DecryptToken(tokenString string) (string, error) { return tokenString, nil // TODO: impl } -func ParseToken(tokenString string, claims interface{}) ([]byte, error) { +func ParseToken(tokenString string, claims any) ([]byte, error) { parts := strings.Split(tokenString, ".") if len(parts) != 3 { return nil, fmt.Errorf("%w: token contains an invalid number of segments", ErrParse)