← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-oauth-sha256-digest into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-oauth-sha256-digest into launchpad:master.

Commit message:
Fix lp.services.oauth.model.sha256_digest on Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/392082

hashlib.sha256 requires bytes, so make sure we don't pass text to it.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-oauth-sha256-digest into launchpad:master.
diff --git a/lib/lp/services/oauth/model.py b/lib/lp/services/oauth/model.py
index 1ecb188..a49e34d 100644
--- a/lib/lp/services/oauth/model.py
+++ b/lib/lp/services/oauth/model.py
@@ -82,7 +82,8 @@ def sha256_digest(data):
     this is straightforward because hexdigest() returns that anyway, but in
     Python 2 we must decode.
     """
-    return six.ensure_text(hashlib.sha256(data).hexdigest(), encoding='ASCII')
+    return six.ensure_text(
+        hashlib.sha256(six.ensure_binary(data)).hexdigest(), encoding='ASCII')
 
 
 @implementer(IOAuthConsumer)