diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-09-03 16:46:19 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-09-03 16:46:19 +0200 |
commit | 4d9db1068f572fd25825307c96df7032e95dfc77 (patch) | |
tree | e9bd0ef4c9ea5c36a7060b6b6028db6667d7fabc /tests | |
parent | bb221dff95eab30e6bdbe755a0d4ac0fa6c18e24 (diff) | |
download | pyasn1-4d9db1068f572fd25825307c96df7032e95dfc77.tar.gz |
fix to get explicit tags from substrate to the recovered ASN.1 object
Diffstat (limited to 'tests')
-rw-r--r-- | tests/codec/ber/test_decoder.py | 158 |
1 files changed, 142 insertions, 16 deletions
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py index 575cd52..d2f02ad 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -195,29 +195,40 @@ class ExpTaggedOctetStringDecoderTestCase(unittest.TestCase): )) def testDefMode(self): - assert self.o.isSameTypeWith(decoder.decode( + o, r = decoder.decode( ints2octs((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)) - )[0]) + ) + assert not r + assert self.o == o + assert self.o.tagSet == o.tagSet + assert self.o.isSameTypeWith(o) def testIndefMode(self): - v, s = decoder.decode(ints2octs(( - 101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, - 102, 111, 120, 0, 0, 0, 0))) - assert self.o.isSameTypeWith(v) - assert not s + o, r = decoder.decode( + ints2octs((101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)) + ) + assert not r + assert self.o == o + assert self.o.tagSet == o.tagSet + assert self.o.isSameTypeWith(o) def testDefModeChunked(self): - v, s = decoder.decode(ints2octs(( - 101, 25, 36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, - 110, 32, 4, 3, 102, 111, 120))) - assert self.o.isSameTypeWith(v) - assert not s + o, r = decoder.decode( + ints2octs((101, 25, 36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)) + ) + assert not r + assert self.o == o + assert self.o.tagSet == o.tagSet + assert self.o.isSameTypeWith(o) def testIndefModeChunked(self): - v, s = decoder.decode(ints2octs((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, - 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0))) - assert self.o.isSameTypeWith(v) - assert not s + o, r = decoder.decode( + ints2octs((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0)) + ) + assert not r + assert self.o == o + assert self.o.tagSet == o.tagSet + assert self.o.isSameTypeWith(o) def testDefModeSubst(self): assert decoder.decode( @@ -513,6 +524,27 @@ class SequenceOfDecoderTestCase(unittest.TestCase): ) == (self.s, null) +class ExpTaggedSequenceOfDecoderTestCase(unittest.TestCase): + + def testWithSchema(self): + s = univ.SequenceOf().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)) + s2, r = decoder.decode( + ints2octs((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=s + ) + assert not r + assert s2 == [str2octs('quick brown')] + assert s.tagSet == s2.tagSet + + def testWithoutSchema(self): + s = univ.SequenceOf().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)) + s2, r = decoder.decode( + ints2octs((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + ) + assert not r + assert s2 == [str2octs('quick brown')] + assert s.tagSet == s2.tagSet + + class SequenceOfDecoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.SequenceOf(componentType=univ.OctetString()) @@ -988,6 +1020,100 @@ class SetDecoderWithSchemaTestCase(unittest.TestCase): ) == (self.s, null) +class SequenceOfWithExpTaggedOctetStringDecoder(unittest.TestCase): + def setUp(self): + self.s = univ.SequenceOf( + componentType=univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)) + ) + self.s.setComponentByPosition(0, 'q') + self.s2 = univ.SequenceOf() + + def testDefModeSchema(self): + s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testIndefModeSchema(self): + s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testDefModeNoComponent(self): + s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s2) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testIndefModeNoComponent(self): + s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s2) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testDefModeSchemaless(self): + s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113))) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testIndefModeSchemaless(self): + s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0))) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + +class SequenceWithExpTaggedOctetStringDecoder(unittest.TestCase): + def setUp(self): + self.s = univ.Sequence( + componentType=namedtype.NamedTypes( + namedtype.NamedType( + 'x', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)) + ) + ) + ) + self.s.setComponentByPosition(0, 'q') + self.s2 = univ.Sequence() + + def testDefModeSchema(self): + s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testIndefModeSchema(self): + s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testDefModeNoComponent(self): + s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113)), asn1Spec=self.s2) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testIndefModeNoComponent(self): + s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0)), asn1Spec=self.s2) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testDefModeSchemaless(self): + s, r = decoder.decode(ints2octs((48, 5, 163, 3, 4, 1, 113))) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + def testIndefModeSchemaless(self): + s, r = decoder.decode(ints2octs((48, 128, 163, 128, 4, 1, 113, 0, 0, 0, 0))) + assert not r + assert s == self.s + assert s.tagSet == self.s.tagSet + + class ChoiceDecoderTestCase(unittest.TestCase): def setUp(self): self.s = univ.Choice( |