jwt/signing_method.go

28 lines
575 B
Go
Raw Normal View History

2012-04-18 03:49:21 +04:00
package jwt
import (
"errors"
2012-04-18 23:59:37 +04:00
"fmt"
2012-04-18 03:49:21 +04:00
)
var signingMethods = map[string]func() SigningMethod{}
// Signing method
type SigningMethod interface {
2012-04-18 23:59:37 +04:00
Verify(signingString, signature string, key []byte) error
Sign(token *Token, key []byte) error
2012-04-18 03:49:21 +04:00
}
func RegisterSigningMethod(alg string, f func() SigningMethod) {
signingMethods[alg] = f
}
2012-04-18 23:59:37 +04:00
func GetSigningMethod(alg string) (method SigningMethod, err error) {
2012-04-18 03:49:21 +04:00
if methodF, ok := signingMethods[alg]; ok {
method = methodF()
} else {
err = errors.New(fmt.Sprintf("Invalid signing method (alg): %v", method))
}
return
2012-04-18 23:59:37 +04:00
}