summaryrefslogtreecommitdiff
path: root/jwt/algorithms.py
diff options
context:
space:
mode:
authorMark Adams <mark@markadams.me>2015-03-17 19:57:11 -0500
committerMark Adams <mark@markadams.me>2015-03-17 20:40:36 -0500
commit6e6156084de42893d5c883ae9b67536b44e7e47a (patch)
tree58fa4ad982080131c867f6a7796f6371d4b1b336 /jwt/algorithms.py
parent838f82445a1274a7dbd5f57e9729cb4986b29eb8 (diff)
downloadpyjwt-6e6156084de42893d5c883ae9b67536b44e7e47a.tar.gz
Added the ability to specify both a global alg whitelist for a PyJWT object and a whitelist for calls to decode. (Fixes #107)
Diffstat (limited to 'jwt/algorithms.py')
-rw-r--r--jwt/algorithms.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py
index f50787f..4a40cfb 100644
--- a/jwt/algorithms.py
+++ b/jwt/algorithms.py
@@ -18,23 +18,28 @@ except ImportError:
has_crypto = False
-def _register_default_algorithms(pyjwt_obj):
+def get_default_algorithms():
"""
- Registers the algorithms that are implemented by the library.
+ Returns the algorithms that are implemented by the library.
"""
- 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))
+ default_algorithms = {
+ 'none': NoneAlgorithm(),
+ 'HS256': HMACAlgorithm(HMACAlgorithm.SHA256),
+ 'HS384': HMACAlgorithm(HMACAlgorithm.SHA384),
+ 'HS512': HMACAlgorithm(HMACAlgorithm.SHA512)
+ }
if has_crypto:
- pyjwt_obj.register_algorithm('RS256', RSAAlgorithm(RSAAlgorithm.SHA256))
- pyjwt_obj.register_algorithm('RS384', RSAAlgorithm(RSAAlgorithm.SHA384))
- pyjwt_obj.register_algorithm('RS512', RSAAlgorithm(RSAAlgorithm.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))
+ default_algorithms.update({
+ 'RS256': RSAAlgorithm(RSAAlgorithm.SHA256),
+ 'RS384': RSAAlgorithm(RSAAlgorithm.SHA384),
+ 'RS512': RSAAlgorithm(RSAAlgorithm.SHA512),
+ 'ES256': ECAlgorithm(ECAlgorithm.SHA256),
+ 'ES384': ECAlgorithm(ECAlgorithm.SHA384),
+ 'ES512': ECAlgorithm(ECAlgorithm.SHA512)
+ })
+
+ return default_algorithms
class Algorithm(object):