summaryrefslogtreecommitdiff
path: root/jwt/algorithms.py
diff options
context:
space:
mode:
authorMark Adams <mark@markadams.me>2016-08-04 10:56:39 -0500
committerMark Adams <mark@markadams.me>2016-08-04 18:03:31 -0500
commit2fe85a338028162b80b7a7f7436397457a10fa70 (patch)
tree113050ae1d7167bd8fa1c2f26ef75fcc83e4acde /jwt/algorithms.py
parentdaf79c1d2143d969e4ba19ec0692cfac773fa6be (diff)
downloadpyjwt-2fe85a338028162b80b7a7f7436397457a10fa70.tar.gz
Fix a bug where a PEM private key as bytes raises a TypeErrorfix-type-error-on-bytes-key
Diffstat (limited to 'jwt/algorithms.py')
-rw-r--r--jwt/algorithms.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py
index 9c1a7e8..51e8f16 100644
--- a/jwt/algorithms.py
+++ b/jwt/algorithms.py
@@ -1,7 +1,7 @@
import hashlib
import hmac
-from .compat import constant_time_compare, string_types, text_type
+from .compat import binary_type, constant_time_compare, is_string_type
from .exceptions import InvalidKeyError
from .utils import der_to_raw_signature, raw_to_der_signature
@@ -112,10 +112,10 @@ class HMACAlgorithm(Algorithm):
self.hash_alg = hash_alg
def prepare_key(self, key):
- if not isinstance(key, string_types) and not isinstance(key, bytes):
+ if not is_string_type(key):
raise TypeError('Expecting a string- or bytes-formatted key.')
- if isinstance(key, text_type):
+ if not isinstance(key, binary_type):
key = key.encode('utf-8')
invalid_strings = [
@@ -156,8 +156,8 @@ if has_crypto:
isinstance(key, RSAPublicKey):
return key
- if isinstance(key, string_types):
- if isinstance(key, text_type):
+ if is_string_type(key):
+ if not isinstance(key, binary_type):
key = key.encode('utf-8')
try:
@@ -213,8 +213,8 @@ if has_crypto:
isinstance(key, EllipticCurvePublicKey):
return key
- if isinstance(key, string_types):
- if isinstance(key, text_type):
+ if is_string_type(key):
+ if not isinstance(key, binary_type):
key = key.encode('utf-8')
# Attempt to load key. We don't know if it's