mirror of https://github.com/golang-jwt/jwt.git
return an error if the requested hash method hasn't been compiled in
This commit is contained in:
parent
48aa7e5db1
commit
2ef58916cc
8
hmac.go
8
hmac.go
|
@ -47,6 +47,10 @@ func (m *SigningMethodHMAC) Verify(signingString, signature string, key interfac
|
||||||
var sig []byte
|
var sig []byte
|
||||||
var err error
|
var err error
|
||||||
if sig, err = DecodeSegment(signature); err == nil {
|
if sig, err = DecodeSegment(signature); err == nil {
|
||||||
|
if !m.Hash.Available() {
|
||||||
|
return ErrHashUnavailable
|
||||||
|
}
|
||||||
|
|
||||||
hasher := hmac.New(m.Hash.New, keyBytes)
|
hasher := hmac.New(m.Hash.New, keyBytes)
|
||||||
hasher.Write([]byte(signingString))
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
|
@ -62,6 +66,10 @@ func (m *SigningMethodHMAC) Verify(signingString, signature string, key interfac
|
||||||
|
|
||||||
func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) {
|
func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) {
|
||||||
if keyBytes, ok := key.([]byte); ok {
|
if keyBytes, ok := key.([]byte); ok {
|
||||||
|
if !m.Hash.Available() {
|
||||||
|
return "", ErrHashUnavailable
|
||||||
|
}
|
||||||
|
|
||||||
hasher := hmac.New(m.Hash.New, keyBytes)
|
hasher := hmac.New(m.Hash.New, keyBytes)
|
||||||
hasher.Write([]byte(signingString))
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
|
|
3
jwt.go
3
jwt.go
|
@ -22,7 +22,8 @@ type Keyfunc func(*Token) (interface{}, error)
|
||||||
|
|
||||||
// Error constants
|
// Error constants
|
||||||
var (
|
var (
|
||||||
ErrInvalidKey = errors.New("Key is invalid or of invalid type.")
|
ErrInvalidKey = errors.New("Key is invalid or of invalid type.")
|
||||||
|
ErrHashUnavailable = errors.New("The requested Hash function is unavailable")
|
||||||
)
|
)
|
||||||
|
|
||||||
// A JWT Token. Different fields will be used depending on whether you're
|
// A JWT Token. Different fields will be used depending on whether you're
|
||||||
|
|
8
rsa.go
8
rsa.go
|
@ -67,6 +67,9 @@ func (m *SigningMethodRSA) Verify(signingString, signature string, key interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create hasher
|
// Create hasher
|
||||||
|
if !m.Hash.Available() {
|
||||||
|
return ErrHashUnavailable
|
||||||
|
}
|
||||||
hasher := m.Hash.New()
|
hasher := m.Hash.New()
|
||||||
hasher.Write([]byte(signingString))
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
|
@ -91,7 +94,12 @@ func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string,
|
||||||
default:
|
default:
|
||||||
return "", ErrInvalidKey
|
return "", ErrInvalidKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the hasher
|
// Create the hasher
|
||||||
|
if !m.Hash.Available() {
|
||||||
|
return "", ErrHashUnavailable
|
||||||
|
}
|
||||||
|
|
||||||
hasher := m.Hash.New()
|
hasher := m.Hash.New()
|
||||||
hasher.Write([]byte(signingString))
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue