summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2018-09-10 12:51:40 +0300
committerSergey Matveev <stargrave@stargrave.org>2018-09-10 17:52:25 +0300
commitcb9ebe2012c619dea2633b00427898312801a840 (patch)
tree73eaaf8c58cb5ffc205f7e732c3e492ea4b1fc4a
parent73db29cf680d46539f651e742acd1942414ce9a1 (diff)
downloadpyderasn-cb9ebe2012c619dea2633b00427898312801a840.tar.xz
Check for DEFAULTed value also in SET
-rw-r--r--VERSION2
-rw-r--r--doc/news.rst6
-rwxr-xr-xpyderasn.py13
-rw-r--r--tests/test_pyderasn.py24
4 files changed, 30 insertions, 15 deletions
diff --git a/VERSION b/VERSION
index 6324d40..93a848f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.14
+3.15
diff --git a/doc/news.rst b/doc/news.rst
index 81db4f5..4224b3d 100644
--- a/doc/news.rst
+++ b/doc/news.rst
@@ -1,6 +1,12 @@
News
====
+.. _release3.15:
+
+3.15
+----
+* DEFAULT-encoded value is checked also for Set-s, not for Sequences only
+
.. _release3.14:
3.14
diff --git a/pyderasn.py b/pyderasn.py
index 6db8017..7edfc80 100755
--- a/pyderasn.py
+++ b/pyderasn.py
@@ -4803,9 +4803,18 @@ class Set(Sequence):
sub_offset += value_len
vlen += value_len
v = v_tail
- if spec.default is None or value != spec.default: # pragma: no cover
- # SeqMixing.test_encoded_default_accepted covers that place
+ if spec.default is None:
values[name] = value
+ else:
+ if value != spec.default:
+ values[name] = value
+ if ctx.get("strict_default_existence", False):
+ raise DecodeError(
+ "DEFAULT value met",
+ klass=self.__class__,
+ decode_path=sub_decode_path,
+ offset=sub_offset,
+ )
obj = self.__class__(
schema=self.specs,
impl=self.tag,
diff --git a/tests/test_pyderasn.py b/tests/test_pyderasn.py
index adad7e9..7b397f2 100644
--- a/tests/test_pyderasn.py
+++ b/tests/test_pyderasn.py
@@ -5871,18 +5871,18 @@ class TestStrictDefaultExistence(TestCase):
("int%d" % i, Integer(expl=tag_ctxc(i + 1)))
for i in range(count)
]
-
- class Seq(Sequence):
- schema = _schema
- seq = Seq()
- for i in range(count):
- seq["int%d" % i] = Integer(123)
- raw = seq.encode()
- chosen = "int%d" % chosen
- seq.specs[chosen] = seq.specs[chosen](default=123)
- seq.decode(raw)
- with assertRaisesRegex(self, DecodeError, "DEFAULT value met"):
- seq.decode(raw, ctx={"strict_default_existence": True})
+ for klass in (Sequence, Set):
+ class Seq(klass):
+ schema = _schema
+ seq = Seq()
+ for i in range(count):
+ seq["int%d" % i] = Integer(123)
+ raw = seq.encode()
+ chosen_choice = "int%d" % chosen
+ seq.specs[chosen_choice] = seq.specs[chosen_choice](default=123)
+ seq.decode(raw)
+ with assertRaisesRegex(self, DecodeError, "DEFAULT value met"):
+ seq.decode(raw, ctx={"strict_default_existence": True})
class TestX690PrefixedType(TestCase):