]> Cypherpunks.ru repositories - pyderasn.git/commitdiff
Simplify hexenc/hexdec
authorSergey Matveev <stargrave@stargrave.org>
Tue, 24 Aug 2021 14:19:24 +0000 (17:19 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 24 Aug 2021 14:19:30 +0000 (17:19 +0300)
pyderasn.py

index bb62acb437c203fa31ee66e03d6789e302a59fdd..0a6613767d33a846cd18defc5746c72ffa4b890c 100755 (executable)
@@ -1159,8 +1159,6 @@ Now you can print only the specified tree, for example signature algorithm::
 """
 
 from array import array
-from codecs import getdecoder
-from codecs import getencoder
 from collections import namedtuple
 from collections import OrderedDict
 from copy import copy
@@ -1441,20 +1439,16 @@ class BoundsError(ASN1Error):
 # Basic coders
 ########################################################################
 
-_hexdecoder = getdecoder("hex")
-_hexencoder = getencoder("hex")
-
-
 def hexdec(data):
     """Binary data to hexadecimal string convert
     """
-    return _hexdecoder(data)[0]
+    return bytes.fromhex(data)
 
 
 def hexenc(data):
     """Hexadecimal string to binary data convert
     """
-    return _hexencoder(data)[0].decode("ascii")
+    return data.hex()
 
 
 def int_bytes_len(num, byte_len=8):