From 1dc8b80cad4ea88b21c53ad59dd3e1cee3eee7ea Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Tue, 26 May 2015 14:37:00 -0700 Subject: [PATCH] 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. --- src/saml2/s_utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/saml2/s_utils.py b/src/saml2/s_utils.py index 271dea9..3260492 100644 --- a/src/saml2/s_utils.py +++ b/src/saml2/s_utils.py @@ -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: