Skip to content

Commit 70490aa

Browse files
authored
Merge pull request #163 from blag/remove-constant-time-string-compare
Remove constant_time_string_compare
2 parents 9f5ac29 + d7ca2bc commit 70490aa

File tree

2 files changed

+1
-26
lines changed

2 files changed

+1
-26
lines changed

jose/jwk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from jose.constants import ALGORITHMS
77
from jose.exceptions import JWKError
88
from jose.utils import base64url_decode, base64url_encode
9-
from jose.utils import constant_time_string_compare
109
from jose.backends.base import Key
1110

1211
try:
@@ -135,7 +134,7 @@ def sign(self, msg):
135134
return hmac.new(self.prepared_key, msg, self.hash_alg).digest()
136135

137136
def verify(self, msg, sig):
138-
return constant_time_string_compare(sig, self.sign(msg))
137+
return hmac.compare_digest(sig, self.sign(msg))
139138

140139
def to_dict(self):
141140
return {

jose/utils.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,3 @@ def timedelta_total_seconds(delta):
108108
delta (timedelta): A timedelta to convert to seconds.
109109
"""
110110
return delta.days * 24 * 60 * 60 + delta.seconds
111-
112-
113-
def constant_time_string_compare(a, b):
114-
"""Helper for comparing string in constant time, independent
115-
of the python version being used.
116-
117-
Args:
118-
a (str): A string to compare
119-
b (str): A string to compare
120-
"""
121-
122-
try:
123-
return hmac.compare_digest(a, b)
124-
except AttributeError:
125-
126-
if len(a) != len(b):
127-
return False
128-
129-
result = 0
130-
131-
for x, y in zip(a, b):
132-
result |= ord(x) ^ ord(y)
133-
134-
return result == 0

0 commit comments

Comments
 (0)