X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pyderasn.py;h=7178d8104bd7bc5316380e22fd89728fdd495603;hb=1a1b425884f791f8a2a2b99dfe717f09ae274200;hp=4a3692795c3974b760b1a20fd9971c05308c078a;hpb=6e7c396eadd0193a18870650b6c23abbacea1591;p=pyderasn.git diff --git a/pyderasn.py b/pyderasn.py index 4a36927..7178d81 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -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 @@ -1182,7 +1180,13 @@ except ImportError: # pragma: no cover def colored(what, *args, **kwargs): return what -__version__ = "9.0" +try: + from dateutil.tz import UTC as tzUTC +except ImportError: # pragma: no cover + tzUTC = "missing" + + +__version__ = "9.1" __all__ = ( "agg_octet_string", @@ -1441,20 +1445,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): @@ -5247,6 +5247,12 @@ class UTCTime(VisibleString): def todatetime(self): return self._value + def totzdatetime(self): + try: + return self._value.replace(tzinfo=tzUTC) + except TypeError as err: + raise NotImplementedError("Missing dateutil.tz") from err + def __repr__(self): return pp_console_row(next(self.pps())) @@ -6107,7 +6113,7 @@ SequenceState = namedtuple( ) -class SequenceEncode1stMixing: +class SequenceEncode1stMixin: __slots__ = () def _encode1st(self, state): @@ -6121,7 +6127,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 +6625,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 +6828,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