summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2020-04-14 10:48:50 +0300
committerSergey Matveev <stargrave@stargrave.org>2020-04-14 13:08:06 +0300
commit44e10c60d857ea5e631927ac4b23365cc3b80698 (patch)
tree16d92d8fbc46f1199ced433794baec0999528e3e
parentbba84f2f3b5fbc860f51cf76f2f504cb2aa8d899 (diff)
downloadpyderasn-44e10c60d857ea5e631927ac4b23365cc3b80698.tar.xz
Explicitly forbid aware-datetimes usage8.0
-rw-r--r--VERSION2
-rw-r--r--doc/install.rst12
-rw-r--r--doc/news.rst8
-rwxr-xr-xpyderasn.py35
-rw-r--r--tests/test_pyderasn.py9
5 files changed, 46 insertions, 20 deletions
diff --git a/VERSION b/VERSION
index 25b629b..cc40bca 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-7.7
+8.0
diff --git a/doc/install.rst b/doc/install.rst
index b74a184..05a9147 100644
--- a/doc/install.rst
+++ b/doc/install.rst
@@ -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
diff --git a/doc/news.rst b/doc/news.rst
index 6190d51..42fb7dc 100644
--- a/doc/news.rst
+++ b/doc/news.rst
@@ -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
diff --git a/pyderasn.py b/pyderasn.py
index 505f3ba..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.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)
diff --git a/tests/test_pyderasn.py b/tests/test_pyderasn.py
index 8225fc0..90d50e9 100644
--- a/tests/test_pyderasn.py
+++ b/tests/test_pyderasn.py
@@ -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):