2012-04-18 03:49:21 +04:00
|
|
|
package jwt
|
|
|
|
|
|
|
|
var signingMethods = map[string]func() SigningMethod{}
|
|
|
|
|
|
|
|
// Signing method
|
|
|
|
type SigningMethod interface {
|
2014-08-04 22:26:53 +04:00
|
|
|
Verify(signingString, signature string, key interface{}) error
|
|
|
|
Sign(signingString string, key interface{}) (string, error)
|
2012-07-07 02:43:17 +04:00
|
|
|
Alg() string
|
2012-04-18 03:49:21 +04:00
|
|
|
}
|
|
|
|
|
2012-07-07 03:12:33 +04:00
|
|
|
// Register the "alg" name and a factory function for signing method.
|
|
|
|
// This is typically done during init() in the method's implementation
|
2012-04-18 03:49:21 +04:00
|
|
|
func RegisterSigningMethod(alg string, f func() SigningMethod) {
|
|
|
|
signingMethods[alg] = f
|
|
|
|
}
|
|
|
|
|
2012-07-07 03:12:33 +04:00
|
|
|
// Get a signing method from an "alg" string
|
2012-07-07 23:12:49 +04:00
|
|
|
func GetSigningMethod(alg string) (method SigningMethod) {
|
2012-04-18 03:49:21 +04:00
|
|
|
if methodF, ok := signingMethods[alg]; ok {
|
|
|
|
method = methodF()
|
|
|
|
}
|
|
|
|
return
|
2012-04-18 23:59:37 +04:00
|
|
|
}
|