summaryrefslogtreecommitdiff
path: root/jwt/algorithms.py
diff options
context:
space:
mode:
authorMark Adams <mark@markadams.me>2015-03-15 17:40:08 -0500
committerMark Adams <madams@atlassian.com>2015-03-17 14:15:14 -0500
commit4e024325715f1427f532b3376a2ffe28315a6ebc (patch)
tree2de6922be549a953b546ec125f80bb8b98302797 /jwt/algorithms.py
parentd47163117bef52392f314406ad0a4177e2a65e16 (diff)
downloadpyjwt-4e024325715f1427f532b3376a2ffe28315a6ebc.tar.gz
Refactored api.py so that all JWT functions are now part of a PyJWT class.
- Created a singleton instance to preserve jwt.encode, jwt.decode, jwt.register_algorithms existing public APIs - Renamed load and verify_signature to _load and _verify_signature since they are not part of the existing public API - Modified related tests to use PyJWT._load and PyJWT._verify_signature
Diffstat (limited to 'jwt/algorithms.py')
-rw-r--r--jwt/algorithms.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py
index 720d675..4616378 100644
--- a/jwt/algorithms.py
+++ b/jwt/algorithms.py
@@ -1,7 +1,6 @@
import hashlib
import hmac
-from .api import register_algorithm
from .compat import constant_time_compare, string_types, text_type
try:
@@ -18,23 +17,23 @@ except ImportError:
has_crypto = False
-def _register_default_algorithms():
+def _register_default_algorithms(pyjwt_obj):
"""
Registers the algorithms that are implemented by the library.
"""
- register_algorithm('none', NoneAlgorithm())
- register_algorithm('HS256', HMACAlgorithm(HMACAlgorithm.SHA256))
- register_algorithm('HS384', HMACAlgorithm(HMACAlgorithm.SHA384))
- register_algorithm('HS512', HMACAlgorithm(HMACAlgorithm.SHA512))
+ pyjwt_obj.register_algorithm('none', NoneAlgorithm())
+ pyjwt_obj.register_algorithm('HS256', HMACAlgorithm(HMACAlgorithm.SHA256))
+ pyjwt_obj.register_algorithm('HS384', HMACAlgorithm(HMACAlgorithm.SHA384))
+ pyjwt_obj.register_algorithm('HS512', HMACAlgorithm(HMACAlgorithm.SHA512))
if has_crypto:
- register_algorithm('RS256', RSAAlgorithm(RSAAlgorithm.SHA256))
- register_algorithm('RS384', RSAAlgorithm(RSAAlgorithm.SHA384))
- register_algorithm('RS512', RSAAlgorithm(RSAAlgorithm.SHA512))
+ pyjwt_obj.register_algorithm('RS256', RSAAlgorithm(RSAAlgorithm.SHA256()))
+ pyjwt_obj.register_algorithm('RS384', RSAAlgorithm(RSAAlgorithm.SHA384()))
+ pyjwt_obj.register_algorithm('RS512', RSAAlgorithm(RSAAlgorithm.SHA512()))
- register_algorithm('ES256', ECAlgorithm(ECAlgorithm.SHA256))
- register_algorithm('ES384', ECAlgorithm(ECAlgorithm.SHA384))
- register_algorithm('ES512', ECAlgorithm(ECAlgorithm.SHA512))
+ pyjwt_obj.register_algorithm('ES256', ECAlgorithm(ECAlgorithm.SHA256()))
+ pyjwt_obj.register_algorithm('ES384', ECAlgorithm(ECAlgorithm.SHA384()))
+ pyjwt_obj.register_algorithm('ES512', ECAlgorithm(ECAlgorithm.SHA512()))
class Algorithm(object):