diff options
author | Pat Ferate <pferate+github@gmail.com> | 2014-07-16 15:02:13 -0700 |
---|---|---|
committer | Pat Ferate <pferate+github@gmail.com> | 2014-07-16 15:02:13 -0700 |
commit | 82ca356f5672526903380faedd7dddf13f38b9ce (patch) | |
tree | 039641dcb7573621b7212d65030e4008324105d0 /oauth2client/crypt.py | |
parent | 9eec4a513d96526f6c4b73e65b9c65deebd29de8 (diff) | |
download | oauth2client-82ca356f5672526903380faedd7dddf13f38b9ce.tar.gz |
Ensure message is in bytes
Diffstat (limited to 'oauth2client/crypt.py')
-rw-r--r-- | oauth2client/crypt.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/oauth2client/crypt.py b/oauth2client/crypt.py index afcf81d..54980a4 100644 --- a/oauth2client/crypt.py +++ b/oauth2client/crypt.py @@ -112,7 +112,11 @@ try: Returns: string, The signature of the message for the given key. """ - return crypto.sign(self._key, str.encode(message), 'sha256') + try: + message = str.encode(message) + except TypeError: + pass + return crypto.sign(self._key, message, 'sha256') @staticmethod def from_string(key, password='notasecret'): @@ -283,7 +287,7 @@ def _urlsafe_b64encode(raw_bytes): # Make sure our bytes are actually bytes try: raw_bytes = str.encode(raw_bytes) - except TypeError: + except (TypeError, UnicodeDecodeError): pass return bytes.decode(base64.urlsafe_b64encode(raw_bytes)).rstrip('=') @@ -292,7 +296,7 @@ def _urlsafe_b64decode(b64string): # Guard against unicode strings, which base64 can't handle. b64string = b64string.encode('ascii') padded = b64string + b'=' * (4 - len(b64string) % 4) - return bytes.decode(base64.urlsafe_b64decode(padded)) + return base64.urlsafe_b64decode(padded) def _json_encode(data): |