Skip to content

Commit

Permalink
python3 hmac string and bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Mathie committed Apr 24, 2017
1 parent 15a35f9 commit cca2128
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flask_mailgun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MailGunAPI(object):
def __init__(self, config):
self.domain = config['MAILGUN_DOMAIN']
self.api_key = config['MAILGUN_API_KEY']
self.api_key = bytes(config['MAILGUN_API_KEY'])
self.api_url = config.get('MAILGUN_API_URL',
MAILGUN_API_URL)
self.route = config.get('MAILGUN_ROUTE', 'uploads')
Expand Down Expand Up @@ -142,7 +142,7 @@ def verify_email(self, email):
raise MailGunException("Mailbox Error: credential verification failed.", "Not enough parameters")

signature_calc = hmac.new(key=self.api_key,
msg='{}{}'.format(timestamp, token),
msg=bytes('{}{}'.format(timestamp, token)),
digestmod=hashlib.sha256).hexdigest()
if signature != signature_calc:
raise MailGunException("Mailbox Error: credential verification failed.", "Signature doesn't match")
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def sign_email(email, mailgun):
timestamp = int(time())
api_key = mailgun.mailgun_api.api_key
signature = hmac.new(key=api_key,
msg='{}{}'.format(timestamp, token),
msg=bytes('{}{}'.format(timestamp, token)),
digestmod=hashlib.sha256).hexdigest()
email.update(dict(token=token,
timestamp=timestamp,
Expand Down

0 comments on commit cca2128

Please sign in to comment.