From 855c9363a5f5a457f5df947180c1410b1de6a037 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 5 Jul 2022 19:12:44 -0700 Subject: [PATCH] add hexlify compatibility for python 3.6 and 3.7 --- jc/parsers/x509_cert.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jc/parsers/x509_cert.py b/jc/parsers/x509_cert.py index 92164e4e..41d63a29 100644 --- a/jc/parsers/x509_cert.py +++ b/jc/parsers/x509_cert.py @@ -235,7 +235,12 @@ def _i2b(integer: int) -> bytes: def _b2a(byte_string: bytes) -> str: """Convert a byte string to a colon-delimited hex ascii string""" - return binascii.hexlify(byte_string, ':').decode('utf-8') + # need try/except since seperator was only introduced in python 3.8. + # provides compatibility for python 3.6 and 3.7. + try: + return binascii.hexlify(byte_string, ':').decode('utf-8') + except TypeError: + return binascii.hexlify(byte_string).decode('utf-8') def _fix_objects(obj):