This commit is contained in:
liris
2015-10-28 09:16:39 +09:00
parent 8a739079f3
commit 4d5bc1e4e3
2 changed files with 9 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ ChangeLog
- 0.34.0
- Change import style (#203)
- fix attribute error on the older python. (#215)
- 0.33.0

View File

@@ -40,6 +40,12 @@ from ._exceptions import *
__all__ = ["handshake_response", "handshake"]
if hasattr(hmac, "compare_digest"):
compare_digest = hmac.compare_digest
else:
def compare_digest(s1, s2):
return s1 == s2
# websocket supported version.
VERSION = 13
@@ -149,10 +155,7 @@ def _validate(headers, key, subprotocols):
value = (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encode('utf-8')
hashed = base64encode(hashlib.sha1(value).digest()).strip().lower()
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
success = (hashed == result)
else:
success = hmac.compare_digest(hashed, result)
success = compare_digest(hashed, result)
if success:
return True, subproto