summaryrefslogtreecommitdiffstats
path: root/ipapython/p11helper.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2016-01-26 16:35:12 +0100
committerJan Cholasta <jcholast@redhat.com>2016-02-17 10:41:29 +0100
commit5b6a1ce8a81a9dac85f13a4f52b9ddddb822590a (patch)
treecaa3fd7e3496085dc2c51e4312d4dfd31ab1ede9 /ipapython/p11helper.py
parentc3529355a63dc5a005f1ca8f59e020bafb9aa49f (diff)
downloadfreeipa-5b6a1ce8a81a9dac85f13a4f52b9ddddb822590a.tar.gz
freeipa-5b6a1ce8a81a9dac85f13a4f52b9ddddb822590a.tar.xz
freeipa-5b6a1ce8a81a9dac85f13a4f52b9ddddb822590a.zip
p11helper: Port to Python 3
- Use binascii.hexlify instead of encode('hex') - Keep the library name as a text string instead of encoding to bytes https://fedorahosted.org/freeipa/ticket/5638 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipapython/p11helper.py')
-rw-r--r--ipapython/p11helper.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/ipapython/p11helper.py b/ipapython/p11helper.py
index d1f128b48..5ff9ccc4e 100644
--- a/ipapython/p11helper.py
+++ b/ipapython/p11helper.py
@@ -4,6 +4,7 @@
import random
import ctypes.util
+import binascii
import six
from cryptography.hazmat.backends import default_backend
@@ -551,13 +552,13 @@ def char_array_to_unicode(array, l):
def int_to_bytes(value):
try:
- return '{0:x}'.format(value).decode('hex')
- except TypeError:
- return '0{0:x}'.format(value).decode('hex')
+ return binascii.unhexlify('{0:x}'.format(value))
+ except (TypeError, binascii.Error):
+ return binascii.unhexlify('0{0:x}'.format(value))
def bytes_to_int(value):
- return int(value.encode('hex'), 16)
+ return int(binascii.hexlify(value), 16)
def check_return_value(rv, message):
@@ -807,8 +808,6 @@ class P11_Helper(object):
# Parse method args
if isinstance(user_pin, unicode):
user_pin = user_pin.encode()
- if isinstance(library_path, unicode):
- library_path = library_path.encode()
self.slot = slot
try: