summaryrefslogtreecommitdiff
path: root/jwt/contrib/algorithms/pycrypto.py
diff options
context:
space:
mode:
authorMark Adams <mark@markadams.me>2017-03-14 08:04:03 -0500
committerMark Adams <mark@markadams.me>2017-03-14 10:43:58 -0500
commitd04339de54fca44c09ae9105627ab4ae7e0abdb1 (patch)
treedcfdd94edb8d89b2222949ead86694a9e1720be8 /jwt/contrib/algorithms/pycrypto.py
parent1710c1524c69c39dfece7a24b87179be5eeff217 (diff)
downloadpyjwt-fix-key-errors.tar.gz
Refactor error handling in Algorithm.prepare_key() methodsfix-key-errors
Our error handling in Algorithm.prepare_key() was previously weird and kind of inconsistent. This change makes a number of improvements: * Refactors RSA and ECDSA prepare_key() methods to reduce nesting and make the code simpler to understand * All calls to Algorithm.prepare_key() return InvalidKeyError (or a subclass) or a valid key instance. * Created a new InvalidAsymmetricKeyError class that is used to provide a standard message when an invalid RSA or ECDSA key is used.
Diffstat (limited to 'jwt/contrib/algorithms/pycrypto.py')
-rw-r--r--jwt/contrib/algorithms/pycrypto.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/jwt/contrib/algorithms/pycrypto.py b/jwt/contrib/algorithms/pycrypto.py
index e6afaa5..fe477db 100644
--- a/jwt/contrib/algorithms/pycrypto.py
+++ b/jwt/contrib/algorithms/pycrypto.py
@@ -7,6 +7,7 @@ from Crypto.Signature import PKCS1_v1_5
from jwt.algorithms import Algorithm
from jwt.compat import string_types, text_type
+from jwt.exceptions import InvalidAsymmetricKeyError
class RSAAlgorithm(Algorithm):
@@ -36,7 +37,7 @@ class RSAAlgorithm(Algorithm):
key = RSA.importKey(key)
else:
- raise TypeError('Expecting a PEM- or RSA-formatted key.')
+ raise InvalidAsymmetricKeyError
return key