From 4e024325715f1427f532b3376a2ffe28315a6ebc Mon Sep 17 00:00:00 2001 From: Mark Adams Date: Sun, 15 Mar 2015 17:40:08 -0500 Subject: 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 --- jwt/algorithms.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'jwt/algorithms.py') 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): -- cgit v1.2.1