Skip to content

Commit

Permalink
Update signature checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Oct 28, 2016
1 parent 34c302f commit 636b61e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pyqiwi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def _urlencode(self, params):
# type: (dict) -> str
return urllib.urlencode({k: v for k, v in params.items() if v})

def _make_signature(self, data):
# type: (dict) -> str
joined = u'|'.join(data[key] for key in sorted(data.keys()))
return base64.b64encode(hmac.new(
self.notification_password, joined.encode('utf-8'), hashlib.sha1
).digest())

def _request(self, url, data=None, method='GET'):
# type: (str, dict, str) -> dict
request = urllib2.Request(url, headers={
Expand Down Expand Up @@ -194,6 +201,4 @@ def check_signature(self, signature, data):
:param data: HTTP post data dict
:return:
"""
joined = '|'.join(data[key] for key in sorted(data.keys()))
return signature == base64.b64encode(hmac.new(
self.notification_password, joined, hashlib.sha1).digest())
return self._make_signature(data) == signature

0 comments on commit 636b61e

Please sign in to comment.