Skip to content

Commit 143b1fb

Browse files
committed
deprecate the constant time bytes comparison path old python 2.7.x uses
1 parent 8ac485d commit 143b1fb

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Changelog
1010

1111
* Added :meth:`~cryptography.fernet.Fernet.extract_timestamp` to get the
1212
authenticated timestamp of a :doc:`Fernet </fernet>` token.
13+
* Support for Python 2.7.x without ``hmac.compare_digest`` has been deprecated.
14+
We will require Python 2.7.7 or higher (or 2.7.6 on Ubuntu) in the next
15+
``cryptography`` release.
1316

1417
.. _v2-2-2:
1518

src/cryptography/hazmat/primitives/constant_time.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from __future__ import absolute_import, division, print_function
66

77
import hmac
8+
import warnings
89

10+
from cryptography import utils
911
from cryptography.hazmat.bindings._constant_time import lib
1012

1113

@@ -17,6 +19,12 @@ def bytes_eq(a, b):
1719
return hmac.compare_digest(a, b)
1820

1921
else:
22+
warnings.warn(
23+
"Support for your Python version is deprecated. The next version of "
24+
"cryptography will remove support. Please upgrade to a 2.7.x "
25+
"release that supports hmac.compare_digest as soon as possible.",
26+
utils.DeprecatedIn23,
27+
)
2028
def bytes_eq(a, b):
2129
if not isinstance(a, bytes) or not isinstance(b, bytes):
2230
raise TypeError("a and b must be bytes.")

src/cryptography/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CryptographyDeprecationWarning(UserWarning):
2222
# cycle ends.
2323
PersistentlyDeprecated = CryptographyDeprecationWarning
2424
DeprecatedIn21 = CryptographyDeprecationWarning
25+
DeprecatedIn23 = CryptographyDeprecationWarning
2526

2627

2728
def _check_bytes(name, value):

0 commit comments

Comments
 (0)