]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - pyderasn.py
Simplify hexenc/hexdec
[pyderasn.git] / pyderasn.py
index 4a3692795c3974b760b1a20fd9971c05308c078a..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):
@@ -6107,7 +6101,7 @@ SequenceState = namedtuple(
 )
 
 
-class SequenceEncode1stMixing:
+class SequenceEncode1stMixin:
     __slots__ = ()
 
     def _encode1st(self, state):
@@ -6121,7 +6115,7 @@ class SequenceEncode1stMixing:
         return len(self.tag) + len_size(vlen) + vlen, state
 
 
-class Sequence(SequenceEncode1stMixing, Obj):
+class Sequence(SequenceEncode1stMixin, Obj):
     """``SEQUENCE`` structure type
 
     You have to make specification of sequence::
@@ -6619,7 +6613,7 @@ class Sequence(SequenceEncode1stMixing, Obj):
             yield pp
 
 
-class Set(Sequence, SequenceEncode1stMixing):
+class Set(Sequence, SequenceEncode1stMixin):
     """``SET`` structure type
 
     Its usage is identical to :py:class:`pyderasn.Sequence`.
@@ -6822,7 +6816,7 @@ SequenceOfState = namedtuple(
 )
 
 
-class SequenceOf(SequenceEncode1stMixing, Obj):
+class SequenceOf(SequenceEncode1stMixin, Obj):
     """``SEQUENCE OF`` sequence type
 
     For that kind of type you must specify the object it will carry on