summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2020-02-10 12:38:17 +0300
committerSergey Matveev <stargrave@stargrave.org>2020-02-10 12:46:43 +0300
commit5e98515aa98abf6ad1f650078551e6543d431b99 (patch)
tree9a65ea97253f2cde5c3fd7f6748cdd1236fc52e5
parentec180a333b81b220e5325bdba75dcbc44b4311c6 (diff)
downloadpyderasn-5e98515aa98abf6ad1f650078551e6543d431b99.tar.xz
Fully strict integers validation in *Time
-rw-r--r--VERSION2
-rw-r--r--doc/install.rst12
-rw-r--r--doc/news.rst7
-rwxr-xr-xpyderasn.py10
-rw-r--r--tests/test_pyderasn.py15
5 files changed, 34 insertions, 12 deletions
diff --git a/VERSION b/VERSION
index a435f5a..0cda48a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-6.1
+6.2
diff --git a/doc/install.rst b/doc/install.rst
index bd3adc8..9c21d28 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-6.1.tar.xz
- $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-6.1.tar.xz.sig
- $ gpg --verify pyderasn-6.1.tar.xz.sig pyderasn-6.1.tar.xz
- $ xz --decompress --stdout pyderasn-6.1.tar.xz | tar xf -
- $ cd pyderasn-6.1
+ $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-6.2.tar.xz
+ $ [fetch|wget] http://pyderasn.cypherpunks.ru/pyderasn-6.2.tar.xz.sig
+ $ gpg --verify pyderasn-6.2.tar.xz.sig pyderasn-6.2.tar.xz
+ $ xz --decompress --stdout pyderasn-6.2.tar.xz | tar xf -
+ $ cd pyderasn-6.2
$ python setup.py install
# or copy pyderasn.py (+six.py, possibly termcolor.py) to your PYTHONPATH
@@ -19,7 +19,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==6.1 --hash=sha256:TO-BE-FILLED
+ pyderasn==6.2 --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 54bf5c7..baa159d 100644
--- a/doc/news.rst
+++ b/doc/news.rst
@@ -1,6 +1,13 @@
News
====
+.. _release6.2:
+
+6.2
+---
+* Python ``int()``'s accepts even more various non-decimal characters
+ than expected. Make validation fully strict, without relying in ``int()``
+
.. _release6.1:
6.1
diff --git a/pyderasn.py b/pyderasn.py
index ea26eb0..1dbfce0 100755
--- a/pyderasn.py
+++ b/pyderasn.py
@@ -690,7 +690,7 @@ except ImportError: # pragma: no cover
def colored(what, *args, **kwargs):
return what
-__version__ = "6.1"
+__version__ = "6.2"
__all__ = (
"Any",
@@ -765,15 +765,15 @@ EOC_LEN = len(EOC)
LENINDEF = b"\x80" # length indefinite mark
LENINDEF_PP_CHAR = "I" if PY2 else "∞"
NAMEDTUPLE_KWARGS = {} if PY2 else {"module": __name__}
-SET01 = frozenset(("0", "1"))
+SET01 = frozenset("01")
+DECIMALS = frozenset("0123456789")
DECIMAL_SIGNS = ".,"
def pureint(value):
- i = int(value)
- if (value[0] in "+- ") or (value[-1] == " "):
+ if not set(value) <= DECIMALS:
raise ValueError("non-pure integer")
- return i
+ return int(value)
def fractions2float(fractions_raw):
pureint(fractions_raw)
diff --git a/tests/test_pyderasn.py b/tests/test_pyderasn.py
index b7ee9a9..1c2f9b0 100644
--- a/tests/test_pyderasn.py
+++ b/tests/test_pyderasn.py
@@ -4305,6 +4305,14 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
b"200001020304+5Z",
b"20000102030405.+6Z",
b"20000102030405.-6Z",
+ b"_2000102030405Z",
+ b"2000_102030405Z",
+ b"200001_2030405Z",
+ b"20000102_30405Z",
+ b"2000010203_405Z",
+ b"200001020304_5Z",
+ b"20000102030405._6Z",
+ b"20000102030405.6_Z",
b" 2000102030405Z",
b"2000 102030405Z",
b"200001 2030405Z",
@@ -4406,6 +4414,13 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase):
b"000102+30405Z",
b"00010203+405Z",
b"0001020304+5Z",
+ b"_10102030405Z",
+ b"00_102030405Z",
+ b"0001_2030405Z",
+ b"000102_30405Z",
+ b"00010203_405Z",
+ b"0001020304_5Z",
+ b"00010203045_Z",
b" 10102030405Z",
b"00 102030405Z",
b"0001 2030405Z",