From 224f53452dee4b8a69312a2d3a9215a0e458d4ba Mon Sep 17 00:00:00 2001 From: Dave Grijalva Date: Sat, 7 Jul 2012 12:12:49 -0700 Subject: [PATCH] fixes --- jwt.go | 4 +++- signing_method.go | 9 +-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/jwt.go b/jwt.go index 8a55ed2..2d8fce8 100644 --- a/jwt.go +++ b/jwt.go @@ -33,6 +33,7 @@ func New(method SigningMethod) *Token { "alg": method.Alg(), }, Claims: make(map[string]interface{}), + Method: method, } } @@ -101,7 +102,8 @@ func Parse(tokenString string, keyFunc Keyfunc) (token *Token, err error) { // Lookup signature method if method, ok := token.Header["alg"].(string); ok { - if token.Method, err = GetSigningMethod(method); err != nil { + if token.Method = GetSigningMethod(method); token.Method == nil { + err = errors.New("Signing method (alg) is unavailable.") return } } else { diff --git a/signing_method.go b/signing_method.go index 6d11817..00e7dad 100644 --- a/signing_method.go +++ b/signing_method.go @@ -1,10 +1,5 @@ package jwt -import ( - "errors" - "fmt" -) - var signingMethods = map[string]func() SigningMethod{} // Signing method @@ -21,11 +16,9 @@ func RegisterSigningMethod(alg string, f func() SigningMethod) { } // Get a signing method from an "alg" string -func GetSigningMethod(alg string) (method SigningMethod, err error) { +func GetSigningMethod(alg string) (method SigningMethod) { if methodF, ok := signingMethods[alg]; ok { method = methodF() - } else { - err = errors.New(fmt.Sprintf("Invalid signing method (alg): %v", method)) } return }