Make s_utils.signature work in python3

This function will need to be extended to work with more character sets
if utf-8 is not enough.
This commit is contained in:
Clint Byrum
2015-05-26 14:37:00 -07:00
parent 994d11b358
commit 1dc8b80cad

View File

@@ -372,8 +372,16 @@ def factory(klass, **kwargs):
def signature(secret, parts):
"""Generates a signature.
"""Generates a signature. All strings are assumed to be utf-8
"""
if not isinstance(secret, six.binary_type):
secret = secret.encode('utf-8')
newparts = []
for part in parts:
if not isinstance(part, six.binary_type):
part = part.encode('utf-8')
newparts.append(part)
parts = newparts
if sys.version_info >= (2, 5):
csum = hmac.new(secret, digestmod=hashlib.sha1)
else: