From 66e2e01a4f364d3554279003b3e7256b6116ce55 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Sun, 19 Feb 2023 16:22:09 +0100 Subject: [PATCH] Unexported some functions and types --- map_claims.go | 24 ++++++++++++------------ validator.go | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/map_claims.go b/map_claims.go index c1a21b1..014acb9 100644 --- a/map_claims.go +++ b/map_claims.go @@ -10,38 +10,38 @@ type MapClaims map[string]interface{} // GetExpirationTime implements the Claims interface. func (m MapClaims) GetExpirationTime() (*NumericDate, error) { - return m.ParseNumericDate("exp") + return m.parseNumericDate("exp") } // GetNotBefore implements the Claims interface. func (m MapClaims) GetNotBefore() (*NumericDate, error) { - return m.ParseNumericDate("nbf") + return m.parseNumericDate("nbf") } // GetIssuedAt implements the Claims interface. func (m MapClaims) GetIssuedAt() (*NumericDate, error) { - return m.ParseNumericDate("iat") + return m.parseNumericDate("iat") } // GetAudience implements the Claims interface. func (m MapClaims) GetAudience() (ClaimStrings, error) { - return m.ParseClaimsString("aud") + return m.parseClaimsString("aud") } // GetIssuer implements the Claims interface. func (m MapClaims) GetIssuer() (string, error) { - return m.ParseString("iss") + return m.parseString("iss") } // GetSubject implements the Claims interface. func (m MapClaims) GetSubject() (string, error) { - return m.ParseString("sub") + return m.parseString("sub") } -// ParseNumericDate tries to parse a key in the map claims type as a number +// parseNumericDate tries to parse a key in the map claims type as a number // date. This will succeed, if the underlying type is either a [float64] or a // [json.Number]. Otherwise, nil will be returned. -func (m MapClaims) ParseNumericDate(key string) (*NumericDate, error) { +func (m MapClaims) parseNumericDate(key string) (*NumericDate, error) { v, ok := m[key] if !ok { return nil, nil @@ -63,9 +63,9 @@ func (m MapClaims) ParseNumericDate(key string) (*NumericDate, error) { return nil, ErrInvalidType } -// ParseClaimsString tries to parse a key in the map claims type as a +// parseClaimsString tries to parse a key in the map claims type as a // [ClaimsStrings] type, which can either be a string or an array of string. -func (m MapClaims) ParseClaimsString(key string) (ClaimStrings, error) { +func (m MapClaims) parseClaimsString(key string) (ClaimStrings, error) { var cs []string switch v := m[key].(type) { case string: @@ -85,10 +85,10 @@ func (m MapClaims) ParseClaimsString(key string) (ClaimStrings, error) { return cs, nil } -// ParseString tries to parse a key in the map claims type as a [string] type. +// parseString tries to parse a key in the map claims type as a [string] type. // If the key does not exist, an empty string is returned. If the key has the // wrong type, an error is returned. -func (m MapClaims) ParseString(key string) (string, error) { +func (m MapClaims) parseString(key string) (string, error) { var ( ok bool raw interface{} diff --git a/validator.go b/validator.go index 2363621..6097d7d 100644 --- a/validator.go +++ b/validator.go @@ -38,9 +38,9 @@ type validator struct { expectedSub string } -// CustomClaims represents a custom claims interface, which can be built upon the integrated +// customClaims represents a custom claims interface, which can be built upon the integrated // claim types, such as map claims or registered claims. -type CustomClaims interface { +type customClaims interface { // CustomValidation can be implemented by a user-specific claim to support // additional validation steps in addition to the regular validation. CustomValidation() error @@ -106,7 +106,7 @@ func (v *validator) Validate(claims Claims) error { // Finally, we want to give the claim itself some possibility to do some // additional custom validation based on a custom function - cvt, ok := claims.(CustomClaims) + cvt, ok := claims.(customClaims) if ok { if err := cvt.CustomValidation(); err != nil { vErr.Inner = err