X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pyderasn.py;h=82021efab0391507dfda7e3d53402d71850cc037;hb=c6cf876ed3979538eeb0f0df60512c3feedb4715;hp=4a3692795c3974b760b1a20fd9971c05308c078a;hpb=6e7c396eadd0193a18870650b6c23abbacea1591;p=pyderasn.git diff --git a/pyderasn.py b/pyderasn.py index 4a36927..82021ef 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 tzutc +except ImportError: # pragma: no cover + tzutc = None + + +__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,13 @@ class UTCTime(VisibleString): def todatetime(self): return self._value + def totzdatetime(self): + if tzutc is None: + raise NotImplementedError( + "Package python-dateutil is required to use this feature", + ) + return self._value.replace(tzinfo=tzutc()) + def __repr__(self): return pp_console_row(next(self.pps())) @@ -6107,7 +6114,7 @@ SequenceState = namedtuple( ) -class SequenceEncode1stMixing: +class SequenceEncode1stMixin: __slots__ = () def _encode1st(self, state): @@ -6121,7 +6128,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 +6626,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 +6829,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