summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2017-08-05 15:26:38 +0200
committerIlya Etingof <etingof@gmail.com>2017-08-05 15:26:38 +0200
commit837037cf186dc901767b90404efcb4cab95612aa (patch)
tree50e274dbffe018e5f5f2fbd8d73020cb7fdfdd78 /tests
parent7b065a33883f413acfc20e6ce12d5ba0597feb19 (diff)
downloadpyasn1-git-837037cf186dc901767b90404efcb4cab95612aa.tar.gz
fix to SetOf components ordering at DER/CER encoder
Diffstat (limited to 'tests')
-rw-r--r--tests/codec/cer/test_encoder.py33
-rw-r--r--tests/codec/der/test_encoder.py32
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/codec/cer/test_encoder.py b/tests/codec/cer/test_encoder.py
index 1ff12db..a1419fd 100644
--- a/tests/codec/cer/test_encoder.py
+++ b/tests/codec/cer/test_encoder.py
@@ -214,6 +214,39 @@ class UTCTimeEncoderTestCase(unittest.TestCase):
) == ints2octs((23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90))
+class SetOfEncoderTestCase(unittest.TestCase):
+ def setUp(self):
+ self.s = univ.SetOf(componentType=univ.OctetString())
+
+ def testIndefMode1(self):
+ self.s.clear()
+ self.s.append('a')
+ self.s.append('ab')
+
+ assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0))
+
+ def testIndefMode2(self):
+ self.s.clear()
+ self.s.append('ab')
+ self.s.append('a')
+
+ assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0))
+
+ def testIndefMode3(self):
+ self.s.clear()
+ self.s.append('b')
+ self.s.append('a')
+
+ assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
+
+ def testIndefMode4(self):
+ self.s.clear()
+ self.s.append('a')
+ self.s.append('b')
+
+ assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
+
+
class NestedOptionalSequenceEncoderTestCase(unittest.TestCase):
def setUp(self):
inner = univ.Sequence(
diff --git a/tests/codec/der/test_encoder.py b/tests/codec/der/test_encoder.py
index eee2707..d30dfc1 100644
--- a/tests/codec/der/test_encoder.py
+++ b/tests/codec/der/test_encoder.py
@@ -43,6 +43,38 @@ class BitStringEncoderTestCase(unittest.TestCase):
) == ints2octs((3, 2, 7, 128))
+class SetOfEncoderTestCase(unittest.TestCase):
+ def setUp(self):
+ self.s = univ.SetOf(componentType=univ.OctetString())
+
+ def testDefMode1(self):
+ self.s.clear()
+ self.s.append('a')
+ self.s.append('ab')
+
+ assert encoder.encode(self.s) == ints2octs((49, 7, 4, 1, 97, 4, 2, 97, 98))
+
+ def testDefMode2(self):
+ self.s.clear()
+ self.s.append('ab')
+ self.s.append('a')
+
+ assert encoder.encode(self.s) == ints2octs((49, 7, 4, 1, 97, 4, 2, 97, 98))
+
+ def testDefMode3(self):
+ self.s.clear()
+ self.s.append('b')
+ self.s.append('a')
+
+ assert encoder.encode(self.s) == ints2octs((49, 6, 4, 1, 97, 4, 1, 98))
+
+ def testDefMode4(self):
+ self.s.clear()
+ self.s.append('a')
+ self.s.append('b')
+
+ assert encoder.encode(self.s) == ints2octs((49, 6, 4, 1, 97, 4, 1, 98))
+
class SetWithChoiceEncoderTestCase(unittest.TestCase):
def setUp(self):
c = univ.Choice(componentType=namedtype.NamedTypes(