]> Cypherpunks.ru repositories - pyderasn.git/commitdiff
Explicitly forbid aware-datetimes usage 8.0
authorSergey Matveev <stargrave@stargrave.org>
Tue, 14 Apr 2020 07:48:50 +0000 (10:48 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 14 Apr 2020 10:08:06 +0000 (13:08 +0300)
VERSION
doc/install.rst
doc/news.rst
pyderasn.py
tests/test_pyderasn.py

diff --git a/VERSION b/VERSION
index 25b629b0aa965f22239cb0927c9a3731a34d2c04..cc40bca69a0ca08256b17fdb5f4a1210364ea597 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-7.7
+8.0
index b74a184aa7d36228fd9cecf88d2b91181df9dad6..05a9147d44a537d98bfe1bd9a76c2a75d0b3885f 100644 (file)
@@ -4,11 +4,11 @@ Install
 Preferable way is to :ref:`download <download>` tarball with the
 signature from `official website <http://pyderasn.cypherpunks.ru/>`__::
 
-    $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-7.7.tar.xz
-    $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-7.7.tar.xz.sig
-    $ gpg --verify pyderasn-7.7.tar.xz.sig pyderasn-7.7.tar.xz
-    $ xz --decompress --stdout pyderasn-7.7.tar.xz | tar xf -
-    $ cd pyderasn-7.7
+    $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-8.0.tar.xz
+    $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-8.0.tar.xz.sig
+    $ gpg --verify pyderasn-8.0.tar.xz.sig pyderasn-8.0.tar.xz
+    $ xz --decompress --stdout pyderasn-8.0.tar.xz | tar xf -
+    $ cd pyderasn-8.0
     $ python setup.py install
     # or copy pyderasn.py (+six.py, possibly termcolor.py) to your PYTHONPATH
 
@@ -21,7 +21,7 @@ You can also find it mirrored on :ref:`download <download>` page.
 You could use pip (**no** OpenPGP authentication is performed!) with PyPI::
 
     $ cat > requirements.txt <<EOF
-    pyderasn==7.7 --hash=sha256:TO-BE-FILLED
+    pyderasn==8.0 --hash=sha256:TO-BE-FILLED
     six==1.14.0 --hash=sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a
     EOF
     $ pip install --requirement requirements.txt
index 6190d51539231dc214b95f1ba52d79ed57b10bff..42fb7dc5e3df916fc81e1c36ba5d8ebdedc7f3d6 100644 (file)
@@ -1,6 +1,14 @@
 News
 ====
 
+.. _release8.0:
+
+8.0
+---
+* **Incompatible** change: explicitly check that only naive datetime
+  objects are used for UTCTime and GeneralizedTime, raise an error
+  otherwise. Previously they silently ignored ``tzinfo``
+
 .. _release7.7:
 
 7.7
index 505f3baafac8516084242256bb12f2633f02ace0..516715a7f2e419a6d1070c03eee7f2c07bb1b895 100755 (executable)
@@ -1201,7 +1201,7 @@ except ImportError:  # pragma: no cover
     def colored(what, *args, **kwargs):
         return what
 
-__version__ = "7.7"
+__version__ = "8.0"
 
 __all__ = (
     "agg_octet_string",
@@ -5080,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
@@ -5213,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))
 
@@ -5323,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)
index 8225fc02eaef4be07fc42093a3f28e4cbc88b933..90d50e9597a0cab8f7f101b9fa5f93abd3ae647a 100644 (file)
@@ -33,6 +33,7 @@ from time import mktime
 from time import time
 from unittest import TestCase
 
+from dateutil.tz import UTC
 from hypothesis import assume
 from hypothesis import given
 from hypothesis import settings
@@ -4727,6 +4728,10 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
             with self.assertRaises(DecodeError):
                 GeneralizedTime(data)
 
+    def test_aware(self):
+        with assertRaisesRegex(self, ValueError, "only naive"):
+            GeneralizedTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
+
 
 class TestUTCTime(TimeMixin, CommonMixin, TestCase):
     base_klass = UTCTime
@@ -5060,6 +5065,10 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase):
                 junk
             )
 
+    def test_aware(self):
+        with assertRaisesRegex(self, ValueError, "only naive"):
+            UTCTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
+
 
 @composite
 def tlv_value_strategy(draw):