diff options
Diffstat (limited to 'tests/codec/der/test_encoder.py')
-rw-r--r-- | tests/codec/der/test_encoder.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/codec/der/test_encoder.py b/tests/codec/der/test_encoder.py index 66a8a91..e06c769 100644 --- a/tests/codec/der/test_encoder.py +++ b/tests/codec/der/test_encoder.py @@ -13,7 +13,7 @@ except ImportError: from tests.base import BaseTestCase -from pyasn1.type import namedtype, univ +from pyasn1.type import tag, namedtype, univ from pyasn1.codec.der import encoder from pyasn1.compat.octets import ints2octs @@ -76,7 +76,8 @@ class SetOfEncoderTestCase(BaseTestCase): assert encoder.encode(self.s) == ints2octs((49, 6, 4, 1, 97, 4, 1, 98)) -class SetWithChoiceEncoderTestCase(BaseTestCase): + +class SetWithAlternatingChoiceEncoderTestCase(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -101,6 +102,49 @@ class SetWithChoiceEncoderTestCase(BaseTestCase): assert encoder.encode(self.s) == ints2octs((49, 6, 1, 1, 255, 2, 1, 5)) +class SetWithTaggedChoiceEncoderTestCase(BaseTestCase): + + def testWithUntaggedChoice(self): + + c = univ.Choice( + componentType=namedtype.NamedTypes( + namedtype.NamedType('premium', univ.Boolean()) + ) + ) + + s = univ.Set( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()), + namedtype.NamedType('customer', c) + ) + ) + + s.setComponentByName('name', 'A') + s.getComponentByName('customer').setComponentByName('premium', True) + + assert encoder.encode(s) == ints2octs((49, 6, 1, 1, 255, 4, 1, 65)) + + def testWithTaggedChoice(self): + + c = univ.Choice( + componentType=namedtype.NamedTypes( + namedtype.NamedType('premium', univ.Boolean()) + ) + ).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7)) + + s = univ.Set( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()), + namedtype.NamedType('customer', c) + ) + ) + + s.setComponentByName('name', 'A') + s.getComponentByName('customer').setComponentByName('premium', True) + + assert encoder.encode(s) == ints2octs((49, 8, 4, 1, 65, 167, 3, 1, 1, 255)) + + class NestedOptionalSequenceEncoderTestCase(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) |