aboutsummaryrefslogtreecommitdiff
path: root/oauth2client/crypt.py
diff options
context:
space:
mode:
authorPat Ferate <pferate+github@gmail.com>2014-07-16 14:22:44 -0700
committerPat Ferate <pferate+github@gmail.com>2014-07-16 14:22:44 -0700
commit7ac4444d7f9ed7bad7dd67ebee233942fe0c8697 (patch)
tree49125c520ae3d8e83aa6204cbdeff6bf77917813 /oauth2client/crypt.py
parent718399bb7d4301f410b0792f32980b0363078e6a (diff)
downloadoauth2client-7ac4444d7f9ed7bad7dd67ebee233942fe0c8697.tar.gz
Added handling for bytes vs str.
Diffstat (limited to 'oauth2client/crypt.py')
-rw-r--r--oauth2client/crypt.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/oauth2client/crypt.py b/oauth2client/crypt.py
index c64a079..afcf81d 100644
--- a/oauth2client/crypt.py
+++ b/oauth2client/crypt.py
@@ -112,7 +112,7 @@ try:
Returns:
string, The signature of the message for the given key.
"""
- return crypto.sign(self._key, message, 'sha256')
+ return crypto.sign(self._key, str.encode(message), 'sha256')
@staticmethod
def from_string(key, password='notasecret'):
@@ -273,21 +273,26 @@ def _parse_pem_key(raw_key_input):
Returns:
string, The actual key if the contents are from a PEM file, or else None.
"""
- offset = raw_key_input.find('-----BEGIN ')
+ offset = raw_key_input.find(b'-----BEGIN ')
if offset != -1:
return raw_key_input[offset:]
else:
return None
def _urlsafe_b64encode(raw_bytes):
- return base64.urlsafe_b64encode(raw_bytes).rstrip('=')
+ # Make sure our bytes are actually bytes
+ try:
+ raw_bytes = str.encode(raw_bytes)
+ except TypeError:
+ pass
+ return bytes.decode(base64.urlsafe_b64encode(raw_bytes)).rstrip('=')
def _urlsafe_b64decode(b64string):
# Guard against unicode strings, which base64 can't handle.
b64string = b64string.encode('ascii')
- padded = b64string + '=' * (4 - len(b64string) % 4)
- return base64.urlsafe_b64decode(padded)
+ padded = b64string + b'=' * (4 - len(b64string) % 4)
+ return bytes.decode(base64.urlsafe_b64decode(padded))
def _json_encode(data):