From f7288992d27b8f629462eb45c8b9dd3e9face204 Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Tue, 29 Dec 2015 22:51:54 +0100 Subject: [PATCH] split ErrInvalidKey into ErrInvalidType and ErrInvalidKey --- ecdsa.go | 4 ++-- errors.go | 3 ++- hmac.go | 2 +- rsa.go | 2 +- rsa_pss.go | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ecdsa.go b/ecdsa.go index 0518ed1..ed131ef 100644 --- a/ecdsa.go +++ b/ecdsa.go @@ -69,7 +69,7 @@ func (m *SigningMethodECDSA) Verify(signingString, signature string, key interfa case *ecdsa.PublicKey: ecdsaKey = k default: - return ErrInvalidKey + return ErrInvalidType } if len(sig) != 2*m.KeySize { @@ -103,7 +103,7 @@ func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string case *ecdsa.PrivateKey: ecdsaKey = k default: - return "", ErrInvalidKey + return "", ErrInvalidType } // Create the hasher diff --git a/errors.go b/errors.go index e9e788f..1dabcbd 100644 --- a/errors.go +++ b/errors.go @@ -6,7 +6,8 @@ import ( // Error constants var ( - ErrInvalidKey = errors.New("key is invalid or of invalid type") + ErrInvalidKey = errors.New("key is invalid") + ErrInvalidType = errors.New("key is of invalid type") ErrHashUnavailable = errors.New("the requested hash function is unavailable") ErrNoTokenInRequest = errors.New("no token present in request") ) diff --git a/hmac.go b/hmac.go index 192e625..ed77b7b 100644 --- a/hmac.go +++ b/hmac.go @@ -49,7 +49,7 @@ func (m *SigningMethodHMAC) Verify(signingString, signature string, key interfac // Verify the key is the right type keyBytes, ok := key.([]byte) if !ok { - return ErrInvalidKey + return ErrInvalidType } // Decode signature, for comparison diff --git a/rsa.go b/rsa.go index cddffce..4db0b49 100644 --- a/rsa.go +++ b/rsa.go @@ -65,7 +65,7 @@ func (m *SigningMethodRSA) Verify(signingString, signature string, key interface case *rsa.PublicKey: rsaKey = k default: - return ErrInvalidKey + return ErrInvalidType } // Create hasher diff --git a/rsa_pss.go b/rsa_pss.go index b5b7073..5f35b37 100644 --- a/rsa_pss.go +++ b/rsa_pss.go @@ -106,7 +106,7 @@ func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (strin case *rsa.PrivateKey: rsaKey = k default: - return "", ErrInvalidKey + return "", ErrInvalidType } // Create the hasher