X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pyderasn.py;h=516715a7f2e419a6d1070c03eee7f2c07bb1b895;hb=3263b452168d49d704506ba5c258186f3aeea253;hp=15ca386b89894c7c4278fc2914f5ca9c3b44e199;hpb=858cfc57f01b2b31b707fb4f808319ab877003dc;p=pyderasn.git diff --git a/pyderasn.py b/pyderasn.py index 15ca386..516715a 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -1201,7 +1201,7 @@ except ImportError: # pragma: no cover def colored(what, *args, **kwargs): return what -__version__ = "7.6" +__version__ = "8.0" __all__ = ( "agg_octet_string", @@ -1558,6 +1558,10 @@ def tag_strip(data): raise DecodeError("unfinished tag") if indexbytes(data, i) & 0x80 == 0: break + if i == 1 and indexbytes(data, 1) < 0x1F: + raise DecodeError("unexpected long form") + if i > 1 and indexbytes(data, 1) & 0x7F == 0: + raise DecodeError("leading zero byte in tag value") i += 1 return data[:i], i, data[i:] @@ -5076,13 +5080,20 @@ class UTCTime(VisibleString): .. warning:: - Pay attention that UTCTime can not hold full year, so all years - having < 50 years are treated as 20xx, 19xx otherwise, according - to X.509 recommendation. + Only **naive** ``datetime`` objects are supported. + Library assumes that all work is done in UTC. .. warning:: - No strict validation of UTC offsets are made, but very crude: + Pay attention that ``UTCTime`` can not hold full year, so all years + having < 50 years are treated as 20xx, 19xx otherwise, according to + X.509 recommendation. Use ``GeneralizedTime`` instead for + removing ambiguity. + + .. warning:: + + No strict validation of UTC offsets are made (only applicable to + **BER**), but very crude: * minutes are not exceeding 60 * offset value is not exceeding 14 hours @@ -5209,6 +5220,8 @@ class UTCTime(VisibleString): if isinstance(value, self.__class__): return value._value, None if value.__class__ == datetime: + if value.tzinfo is not None: + raise ValueError("only naive datetime supported") return self._dt_sanitize(value), None raise InvalidValueType((self.__class__, datetime)) @@ -5319,23 +5332,23 @@ class GeneralizedTime(UTCTime): .. warning:: - Only microsecond fractions are supported in DER encoding. - :py:exc:`pyderasn.DecodeError` will be raised during decoding of - higher precision values. + Only **naive** datetime objects are supported. + Library assumes that all work is done in UTC. .. warning:: - BER encoded data can loss information (accuracy) during decoding - because of float transformations. + Only **microsecond** fractions are supported in DER encoding. + :py:exc:`pyderasn.DecodeError` will be raised during decoding of + higher precision values. .. warning:: - Local times (without explicit timezone specification) are treated - as UTC one, no transformations are made. + **BER** encoded data can loss information (accuracy) during + decoding because of float transformations. .. warning:: - Zero year is unsupported. + **Zero** year is unsupported. """ __slots__ = () tag_default = tag_encode(24)