diff options
author | Mark Adams <mark@markadams.me> | 2015-01-18 10:36:09 -0600 |
---|---|---|
committer | Mark Adams <mark@markadams.me> | 2015-01-18 10:36:34 -0600 |
commit | 8e2adaefbf9e92e128ea034d6c5ab52dc1053047 (patch) | |
tree | ee8fe3b17bb5dabba448b52420f0c4caa1c7bb0e /jwt/algorithms.py | |
parent | e49582f6d1bad64d3bf5260049aab4eb08a94e70 (diff) | |
download | pyjwt-8e2adaefbf9e92e128ea034d6c5ab52dc1053047.tar.gz |
Fixed a couple of anomalies after the last rebase.
Diffstat (limited to 'jwt/algorithms.py')
-rw-r--r-- | jwt/algorithms.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py index 1fd0ca0..9390636 100644 --- a/jwt/algorithms.py +++ b/jwt/algorithms.py @@ -1,13 +1,8 @@ import hashlib import hmac -import sys from jwt import register_algorithm -from jwt.utils import constant_time_compare - -if sys.version_info >= (3, 0, 0): - unicode = str - basestring = str +from jwt.compat import constant_time_compare, string_types, text_type try: from cryptography.hazmat.primitives import interfaces, hashes @@ -66,10 +61,10 @@ class HMACAlgorithm(Algorithm): self.hash_alg = hash_alg def prepare_key(self, key): - if not isinstance(key, basestring) and not isinstance(key, bytes): + if not isinstance(key, string_types) and not isinstance(key, text_type): raise TypeError('Expecting a string- or bytes-formatted key.') - if isinstance(key, unicode): + if isinstance(key, text_type): key = key.encode('utf-8') return key @@ -92,7 +87,7 @@ if has_crypto: return key if isinstance(key, basestring): - if isinstance(key, unicode): + if isinstance(key, text_type): key = key.encode('utf-8') try: @@ -140,8 +135,8 @@ if has_crypto: isinstance(key, interfaces.EllipticCurvePublicKey): return key - if isinstance(key, basestring): - if isinstance(key, unicode): + if isinstance(key, string_types): + if isinstance(key, text_type): key = key.encode('utf-8') # Attempt to load key. We don't know if it's |