3131except ImportError :
3232 has_crypto = False
3333
34-
35- def _get_crypto_algorithms ():
36- crypto_algorithms = {
37- 'RS256' : None ,
38- 'RS384' : None ,
39- 'RS512' : None ,
40- 'ES256' : None ,
41- 'ES384' : None ,
42- 'ES521' : None ,
43- 'ES512' : None ,
44- 'PS256' : None ,
45- 'PS384' : None ,
46- 'PS512' : None
47- }
48-
49- if has_crypto :
50- crypto_algorithms ['RS256' ] = RSAAlgorithm (RSAAlgorithm .SHA256 )
51- crypto_algorithms ['RS384' ] = RSAAlgorithm (RSAAlgorithm .SHA384 )
52- crypto_algorithms ['RS512' ] = RSAAlgorithm (RSAAlgorithm .SHA512 )
53- crypto_algorithms ['ES256' ] = ECAlgorithm (ECAlgorithm .SHA256 )
54- crypto_algorithms ['ES384' ] = ECAlgorithm (ECAlgorithm .SHA384 )
55- crypto_algorithms ['ES521' ] = ECAlgorithm (ECAlgorithm .SHA512 )
56- crypto_algorithms ['ES512' ] = ECAlgorithm (ECAlgorithm .SHA512 )
57- crypto_algorithms ['PS256' ] = RSAPSSAlgorithm (RSAPSSAlgorithm .SHA256 )
58- crypto_algorithms ['PS384' ] = RSAPSSAlgorithm (RSAPSSAlgorithm .SHA384 )
59- crypto_algorithms ['PS512' ] = RSAPSSAlgorithm (RSAPSSAlgorithm .SHA512 )
60-
61- return crypto_algorithms
34+ requires_cryptography = {'RS256' , 'RS384' , 'RS512' , 'ES256' , 'ES384' , 'ES521' ,
35+ 'ES512' , 'PS256' , 'PS384' , 'PS512' }
6236
6337
6438def get_default_algorithms ():
@@ -73,21 +47,22 @@ def get_default_algorithms():
7347 }
7448
7549 if has_crypto :
76- crypto_algorithms = _get_crypto_algorithms ()
77- default_algorithms .update (crypto_algorithms )
50+ default_algorithms .update ({
51+ 'RS256' : RSAAlgorithm (RSAAlgorithm .SHA256 ),
52+ 'RS384' : RSAAlgorithm (RSAAlgorithm .SHA384 ),
53+ 'RS512' : RSAAlgorithm (RSAAlgorithm .SHA512 ),
54+ 'ES256' : ECAlgorithm (ECAlgorithm .SHA256 ),
55+ 'ES384' : ECAlgorithm (ECAlgorithm .SHA384 ),
56+ 'ES521' : ECAlgorithm (ECAlgorithm .SHA512 ),
57+ 'ES512' : ECAlgorithm (ECAlgorithm .SHA512 ), # Backward compat for #219 fix
58+ 'PS256' : RSAPSSAlgorithm (RSAPSSAlgorithm .SHA256 ),
59+ 'PS384' : RSAPSSAlgorithm (RSAPSSAlgorithm .SHA384 ),
60+ 'PS512' : RSAPSSAlgorithm (RSAPSSAlgorithm .SHA512 )
61+ })
7862
7963 return default_algorithms
8064
8165
82- def get_crypto_algorithms ():
83- """
84- Returns a set of algorithm names that require the cryptography package to
85- be installed in order to use.
86- """
87- crypto_algorithms = _get_crypto_algorithms ().keys ()
88- return set (crypto_algorithms )
89-
90-
9166class Algorithm (object ):
9267 """
9368 The interface for an algorithm used to sign and verify tokens.
0 commit comments