summaryrefslogtreecommitdiff
path: root/jwt/algorithms.py
diff options
context:
space:
mode:
authorLandon GB <landogbland@gmail.com>2016-11-30 09:33:46 -0700
committerLandon GB <landogbland@gmail.com>2016-11-30 09:33:46 -0700
commit0550fa347ed29e2ffcd8f26a3adcf0ddcae6fdc3 (patch)
treec3b7b81d13b8f6b7bdaefe0788ba904ff99b3454 /jwt/algorithms.py
parent8520c8f0e0c9ea13df785e8143ee193f088c008a (diff)
downloadpyjwt-0550fa347ed29e2ffcd8f26a3adcf0ddcae6fdc3.tar.gz
Changes per code review
Diffstat (limited to 'jwt/algorithms.py')
-rw-r--r--jwt/algorithms.py53
1 files changed, 14 insertions, 39 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py
index 77a910d..8360ed9 100644
--- a/jwt/algorithms.py
+++ b/jwt/algorithms.py
@@ -31,34 +31,8 @@ try:
except ImportError:
has_crypto = False
-
-def _get_crypto_algorithms():
- crypto_algorithms = {
- 'RS256': None,
- 'RS384': None,
- 'RS512': None,
- 'ES256': None,
- 'ES384': None,
- 'ES521': None,
- 'ES512': None,
- 'PS256': None,
- 'PS384': None,
- 'PS512': None
- }
-
- if has_crypto:
- crypto_algorithms['RS256'] = RSAAlgorithm(RSAAlgorithm.SHA256)
- crypto_algorithms['RS384'] = RSAAlgorithm(RSAAlgorithm.SHA384)
- crypto_algorithms['RS512'] = RSAAlgorithm(RSAAlgorithm.SHA512)
- crypto_algorithms['ES256'] = ECAlgorithm(ECAlgorithm.SHA256)
- crypto_algorithms['ES384'] = ECAlgorithm(ECAlgorithm.SHA384)
- crypto_algorithms['ES521'] = ECAlgorithm(ECAlgorithm.SHA512)
- crypto_algorithms['ES512'] = ECAlgorithm(ECAlgorithm.SHA512)
- crypto_algorithms['PS256'] = RSAPSSAlgorithm(RSAPSSAlgorithm.SHA256)
- crypto_algorithms['PS384'] = RSAPSSAlgorithm(RSAPSSAlgorithm.SHA384)
- crypto_algorithms['PS512'] = RSAPSSAlgorithm(RSAPSSAlgorithm.SHA512)
-
- return crypto_algorithms
+requires_cryptography = {'RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES521',
+ 'ES512', 'PS256', 'PS384', 'PS512'}
def get_default_algorithms():
@@ -73,21 +47,22 @@ def get_default_algorithms():
}
if has_crypto:
- crypto_algorithms = _get_crypto_algorithms()
- default_algorithms.update(crypto_algorithms)
+ default_algorithms.update({
+ 'RS256': RSAAlgorithm(RSAAlgorithm.SHA256),
+ 'RS384': RSAAlgorithm(RSAAlgorithm.SHA384),
+ 'RS512': RSAAlgorithm(RSAAlgorithm.SHA512),
+ 'ES256': ECAlgorithm(ECAlgorithm.SHA256),
+ 'ES384': ECAlgorithm(ECAlgorithm.SHA384),
+ 'ES521': ECAlgorithm(ECAlgorithm.SHA512),
+ 'ES512': ECAlgorithm(ECAlgorithm.SHA512), # Backward compat for #219 fix
+ 'PS256': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA256),
+ 'PS384': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA384),
+ 'PS512': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA512)
+ })
return default_algorithms
-def get_crypto_algorithms():
- """
- Returns a set of algorithm names that require the cryptography package to
- be installed in order to use.
- """
- crypto_algorithms = _get_crypto_algorithms().keys()
- return set(crypto_algorithms)
-
-
class Algorithm(object):
"""
The interface for an algorithm used to sign and verify tokens.