diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-11-23 01:26:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 01:26:53 +0100 |
commit | 3d7f65f52b1a4b38f7ca561d460a78125dd31df1 (patch) | |
tree | 75dc1f31a5eb88702223cfa9ef0ca85f1cb493e6 /tests/codec/ber/test_decoder.py | |
parent | fa6dda62e11698a2b0f6482c41e7d1d83d6c6404 (diff) | |
download | pyasn1-3d7f65f52b1a4b38f7ca561d460a78125dd31df1.tar.gz |
relax open type field type check on assignment (#105)
Diffstat (limited to 'tests/codec/ber/test_decoder.py')
-rw-r--r-- | tests/codec/ber/test_decoder.py | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py index fdbb205..8374fd0 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -828,7 +828,7 @@ class SequenceDecoderWithSchemaTestCase(BaseTestCase): ) == (self.s, null) -class SequenceDecoderWithIntegerOpenTypesTestCase(BaseTestCase): +class SequenceDecoderWithUnaggedOpenTypesTestCase(BaseTestCase): def setUp(self): openType = opentype.OpenType( 'id', @@ -854,12 +854,34 @@ class SequenceDecoderWithIntegerOpenTypesTestCase(BaseTestCase): 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 + decodeOpenTypes=True ) assert not r assert s[0] == 2 assert s[1] == univ.OctetString('quick brown') + def testDecodeOpenTypesUnknownType(self): + try: + s, r = decoder.decode( + ints2octs((48, 6, 2, 1, 2, 6, 1, 39)), asn1Spec=self.s, + decodeOpenTypes=True + ) + + except PyAsn1Error: + pass + + else: + assert False, 'unknown open type tolerated' + + def testDecodeOpenTypesUnknownId(self): + s, r = decoder.decode( + ints2octs((48, 6, 2, 1, 3, 6, 1, 39)), asn1Spec=self.s, + decodeOpenTypes=True + ) + assert not r + assert s[0] == 3 + assert s[1] == univ.OctetString(hexValue='060127') + def testDontDecodeOpenTypesChoiceOne(self): s, r = decoder.decode( ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s @@ -877,6 +899,72 @@ class SequenceDecoderWithIntegerOpenTypesTestCase(BaseTestCase): assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) +class SequenceDecoderWithImplicitlyTaggedOpenTypesTestCase(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().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)), openType=openType + ) + ) + ) + + def testDecodeOpenTypesChoiceOne(self): + s, r = decoder.decode( + ints2octs((48, 8, 2, 1, 1, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + ) + assert not r + assert s[0] == 1 + assert s[1] == 12 + + def testDecodeOpenTypesUnknownId(self): + s, r = decoder.decode( + ints2octs((48, 8, 2, 1, 3, 131, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + ) + assert not r + assert s[0] == 3 + assert s[1] == univ.OctetString(hexValue='02010C') + + +class SequenceDecoderWithExplicitlyTaggedOpenTypesTestCase(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().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)), openType=openType + ) + ) + ) + + def testDecodeOpenTypesChoiceOne(self): + s, r = decoder.decode( + ints2octs((48, 8, 2, 1, 1, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + ) + assert not r + assert s[0] == 1 + assert s[1] == 12 + + def testDecodeOpenTypesUnknownId(self): + s, r = decoder.decode( + ints2octs((48, 8, 2, 1, 3, 163, 3, 2, 1, 12)), asn1Spec=self.s, decodeOpenTypes=True + ) + assert not r + assert s[0] == 3 + assert s[1] == univ.OctetString(hexValue='02010C') + + class SetDecoderTestCase(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) |