66from jose .constants import ALGORITHMS
77from jose .exceptions import JWKError
88from jose .utils import base64url_decode , base64url_encode
9- from jose .utils import constant_time_string_compare
109from jose .backends .base import Key
1110
1211try :
@@ -36,7 +35,7 @@ def get_key(algorithm):
3635
3736def register_key (algorithm , key_class ):
3837 if not issubclass (key_class , Key ):
39- raise TypeError ("Key class not a subclass of jwk.Key" )
38+ raise TypeError ("Key class is not a subclass of jwk.Key" )
4039 ALGORITHMS .KEYS [algorithm ] = key_class
4140 ALGORITHMS .SUPPORTED .add (algorithm )
4241 return True
@@ -53,11 +52,11 @@ def construct(key_data, algorithm=None):
5352 algorithm = key_data .get ('alg' , None )
5453
5554 if not algorithm :
56- raise JWKError ('Unable to find a algorithm for key: %s' % key_data )
55+ raise JWKError ('Unable to find an algorithm for key: %s' % key_data )
5756
5857 key_class = get_key (algorithm )
5958 if not key_class :
60- raise JWKError ('Unable to find a algorithm for key: %s' % key_data )
59+ raise JWKError ('Unable to find an algorithm for key: %s' % key_data )
6160 return key_class (key_data , algorithm )
6261
6362
@@ -119,7 +118,7 @@ def __init__(self, key, algorithm):
119118
120119 def _process_jwk (self , jwk_dict ):
121120 if not jwk_dict .get ('kty' ) == 'oct' :
122- raise JWKError ("Incorrect key type. Expected: 'oct', Recieved : %s" % jwk_dict .get ('kty' ))
121+ raise JWKError ("Incorrect key type. Expected: 'oct', Received : %s" % jwk_dict .get ('kty' ))
123122
124123 k = jwk_dict .get ('k' )
125124 k = k .encode ('utf-8' )
@@ -132,7 +131,7 @@ def sign(self, msg):
132131 return hmac .new (self .prepared_key , msg , self .hash_alg ).digest ()
133132
134133 def verify (self , msg , sig ):
135- return constant_time_string_compare (sig , self .sign (msg ))
134+ return hmac . compare_digest (sig , self .sign (msg ))
136135
137136 def to_dict (self ):
138137 return {
0 commit comments