@@ -52,25 +52,19 @@ def verify_signature(self, timestamp, signature):
5252 # Python 2.7.6 doesn't support compare_digest
5353 # It's recommended to use Python 2.7.7+
5454 # noqa See https://docs.python.org/2/whatsnew/2.7.html#pep-466-network-security-enhancements-for-python-2-7
55+ req = str .encode ('v0:' + str (timestamp ) + ':' ) + request .get_data ()
56+ request_hash = 'v0=' + hmac .new (
57+ str .encode (self .signing_secret ),
58+ req , hashlib .sha256
59+ ).hexdigest ()
60+
5561 if hasattr (hmac , "compare_digest" ):
56- req = str .encode ('v0:' + str (timestamp ) + ':' ) + request .get_data ()
57- request_hash = 'v0=' + hmac .new (
58- str .encode (self .signing_secret ),
59- req , hashlib .sha256
60- ).hexdigest ()
6162 # Compare byte strings for Python 2
6263 if (sys .version_info [0 ] == 2 ):
6364 return hmac .compare_digest (bytes (request_hash ), bytes (signature ))
6465 else :
6566 return hmac .compare_digest (request_hash , signature )
6667 else :
67- # So, we'll compare the signatures explicitly
68- req = str .encode ('v0:' + str (timestamp ) + ':' ) + request .get_data ()
69- request_hash = 'v0=' + hmac .new (
70- str .encode (self .signing_secret ),
71- req , hashlib .sha256
72- ).hexdigest ()
73-
7468 if len (request_hash ) != len (signature ):
7569 return False
7670 result = 0
@@ -127,6 +121,7 @@ class SlackEventAdapterException(Exception):
127121 """
128122 Base exception for all errors raised by the SlackClient library
129123 """
124+
130125 def __init__ (self , msg = None ):
131126 if msg is None :
132127 # default error message
0 commit comments