Skip to content

Commit 9585327

Browse files
author
Leif Johansson
committed
fixing more python 3 stuff
1 parent 52aa6da commit 9585327

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
idna==2.5
2+
six
23
defusedxml
34
lxml
45
pyconfig

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
version = '0.19dev1'
1313

1414
install_requires = [
15-
'idna==2.5', 'defusedxml', 'lxml', 'pyconfig', 'requests', 'cryptography', 'six'
15+
'defusedxml', 'lxml', 'pyconfig', 'requests', 'cryptography', 'six'
1616
]
1717

1818
# Let some other project depend on 'xmlsec[PKCS11]'

src/xmlsec/crypto.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import logging
55
import threading
66
import six
7+
from six.moves import xrange
8+
from xmlsec import constants
79
from binascii import hexlify
810
from xmlsec.exceptions import XMLSigException
911
from xmlsec.utils import unicode_to_bytes
@@ -12,6 +14,7 @@
1214
from cryptography.hazmat.primitives import serialization, hashes
1315
from cryptography.hazmat.primitives.asymmetric import rsa, padding, utils
1416
from cryptography.x509 import load_pem_x509_certificate, load_der_x509_certificate, Certificate
17+
import codecs
1518

1619
if six.PY2:
1720
from UserDict import DictMixin
@@ -229,7 +232,7 @@ def sign(self, data, hash_alg=None):
229232
msg = r.json()
230233
if not 'signed' in msg:
231234
raise ValueError("Missing signed data in response message")
232-
return msg['signed'].decode('base64')
235+
return codecs.encode(msg['signed'], 'base64')
233236
except Exception as ex:
234237
from traceback import print_exc
235238
print_exc(ex)
@@ -311,7 +314,7 @@ def _cert_fingerprint(cert_pem):
311314
else:
312315
cert = load_der_x509_certificate(base64.standard_b64decode(cert_pem), backend=default_backend())
313316

314-
fingerprint = hexlify(cert.fingerprint(hashes.SHA1())).lower()
317+
fingerprint = hexlify(cert.fingerprint(hashes.SHA1())).lower().decode('ascii')
315318
fingerprint = ":".join([fingerprint[x:x + 2] for x in xrange(0, len(fingerprint), 2)])
316319

317320
return fingerprint, cert

src/xmlsec/test/p11_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import subprocess
1313
import shutil
1414
import tempfile
15+
import codecs
1516

1617
from lxml import etree
1718

@@ -244,7 +245,7 @@ def _get_all_signatures(t):
244245
sv = sig.findtext(".//{%s}SignatureValue" % xmlsec.NS['ds'])
245246
assert sv is not None
246247
# base64-dance to normalize newlines
247-
res.append(sv.decode('base64').encode('base64'))
248+
res.append(codecs.encode(codecs.decode(sv, 'base64'),'base64'))
248249
return res
249250

250251

0 commit comments

Comments
 (0)