aboutsummaryrefslogtreecommitdiff
path: root/tests/codec/ber/test_decoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codec/ber/test_decoder.py')
-rw-r--r--tests/codec/ber/test_decoder.py53
1 files changed, 51 insertions, 2 deletions
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py
index 5ec3a5f..cd7262e 100644
--- a/tests/codec/ber/test_decoder.py
+++ b/tests/codec/ber/test_decoder.py
@@ -12,7 +12,7 @@ except ImportError:
from tests.base import BaseTestCase
-from pyasn1.type import tag, namedtype, univ, char
+from pyasn1.type import tag, namedtype, opentype, univ, char
from pyasn1.codec.ber import decoder, eoo
from pyasn1.compat.octets import ints2octs, str2octs, null
from pyasn1.error import PyAsn1Error
@@ -728,7 +728,7 @@ class SequenceDecoderWithSchemaTestCase(BaseTestCase):
def testDefMode(self):
self.__init()
assert decoder.decode(
- ints2octs((48, 128, 5, 0, 0, 0)), asn1Spec=self.s
+ ints2octs((48, 2, 5, 0)), asn1Spec=self.s
) == (self.s, null)
def testIndefMode(self):
@@ -831,6 +831,55 @@ class SequenceDecoderWithSchemaTestCase(BaseTestCase):
) == (self.s, null)
+class SequenceDecoderWithIntegerOpenTypesTestCase(BaseTestCase):
+ def setUp(self):
+ openType = opentype.OpenType(
+ 'id',
+ {1: univ.Integer(),
+ 2: univ.OctetString()}
+ )
+ self.s = univ.Sequence(
+ componentType=namedtype.NamedTypes(
+ namedtype.NamedType('id', univ.Integer()),
+ namedtype.NamedType('blob', univ.Any(), openType=openType)
+ )
+ )
+
+ def testDecodeOpenTypesChoiceOne(self):
+ s, r = decoder.decode(
+ ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s,
+ decodeOpenTypes=True
+ )
+ assert not r
+ assert s[0] == 1
+ assert s[1] == 12
+
+ def testDecodeOpenTypesChoiceTwo(self):
+ s, r = decoder.decode(
+ ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s,
+ decodeOpenTypes = True
+ )
+ assert not r
+ assert s[0] == 2
+ assert s[1] == univ.OctetString('quick brown')
+
+ def testDontDecodeOpenTypesChoiceOne(self):
+ s, r = decoder.decode(
+ ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s
+ )
+ assert not r
+ assert s[0] == 1
+ assert s[1] == ints2octs((2, 1, 12))
+
+ def testDontDecodeOpenTypesChoiceTwo(self):
+ s, r = decoder.decode(
+ ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s
+ )
+ assert not r
+ assert s[0] == 2
+ assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110))
+
+
class SetDecoderTestCase(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)