diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-08-29 16:00:55 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-08-29 16:00:55 +0200 |
commit | 9441a1c08d5fbb116a7e6b3ec2fddea4e784fd9f (patch) | |
tree | 1847c0e12213719c033b8771dccfe11c5cd2c360 /tests | |
parent | 2b71504897e1703cbe08069f99d34b949db364c0 (diff) | |
download | pyasn1-9441a1c08d5fbb116a7e6b3ec2fddea4e784fd9f.tar.gz |
fixed crash at SEQUENCE/OF encoder, schemaless mode
Diffstat (limited to 'tests')
-rw-r--r-- | tests/codec/ber/test_decoder.py | 12 | ||||
-rw-r--r-- | tests/codec/ber/test_encoder.py | 169 | ||||
-rw-r--r-- | tests/codec/cer/test_encoder.py | 364 |
3 files changed, 466 insertions, 79 deletions
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py index a836250..575cd52 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -507,13 +507,13 @@ class SequenceOfDecoderTestCase(unittest.TestCase): ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) ) == (self.s, null) - def testUnguidedDecoder(self): + def testSchemalessDecoder(self): assert decoder.decode( ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=univ.SequenceOf() ) == (self.s, null) -class GuidedSequenceOfDecoderTestCase(unittest.TestCase): +class SequenceOfDecoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.SequenceOf(componentType=univ.OctetString()) self.s.setComponentByPosition(0, univ.OctetString('quick brown')) @@ -564,13 +564,13 @@ class SetOfDecoderTestCase(unittest.TestCase): ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) ) == (self.s, null) - def testUnguidedDecoder(self): + def testSchemalessDecoder(self): assert decoder.decode( ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=univ.SetOf() ) == (self.s, null) -class GuidedSetOfDecoderTestCase(unittest.TestCase): +class SetOfDecoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.SetOf(componentType=univ.OctetString()) self.s.setComponentByPosition(0, univ.OctetString('quick brown')) @@ -655,7 +655,7 @@ class SequenceDecoderTestCase(unittest.TestCase): assert 0, 'wrong tagFormat worked out' -class GuidedSequenceDecoderTestCase(unittest.TestCase): +class SequenceDecoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.Sequence( componentType=namedtype.NamedTypes( @@ -849,7 +849,7 @@ class SetDecoderTestCase(unittest.TestCase): assert 0, 'wrong tagFormat worked out' -class GuidedSetDecoderTestCase(unittest.TestCase): +class SetDecoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.Set( componentType=namedtype.NamedTypes( diff --git a/tests/codec/ber/test_encoder.py b/tests/codec/ber/test_encoder.py index 8bcdb10..332b071 100644 --- a/tests/codec/ber/test_encoder.py +++ b/tests/codec/ber/test_encoder.py @@ -343,6 +343,38 @@ class UTF8StringEncoderTestCase(unittest.TestCase): class SequenceOfEncoderTestCase(unittest.TestCase): + def testEmpty(self): + s = univ.SequenceOf() + assert encoder.encode(s) == ints2octs((48, 0)) + + def testDefMode(self): + s = univ.SequenceOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode(s) == ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + + def testIndefMode(self): + s = univ.SequenceOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=False + ) == ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + + def testDefModeChunked(self): + s = univ.SequenceOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=True, maxChunkSize=4 + ) == ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + + def testIndefModeChunked(self): + s = univ.SequenceOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=False, maxChunkSize=4 + ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + + +class SequenceOfEncoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.SequenceOf(componentType=univ.OctetString()) @@ -374,8 +406,40 @@ class SequenceOfEncoderTestCase(unittest.TestCase): class SetOfEncoderTestCase(unittest.TestCase): + def testEmpty(self): + s = univ.SetOf() + assert encoder.encode(s) == ints2octs((49, 0)) + + def testDefMode(self): + s = univ.SetOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode(s) == ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + + def testIndefMode(self): + s = univ.SetOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=False + ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + + def testDefModeChunked(self): + s = univ.SetOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=True, maxChunkSize=4 + ) == ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + + def testIndefModeChunked(self): + s = univ.SetOf() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=False, maxChunkSize=4 + ) == ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + + +class SetOfEncoderWithSchemaTestCase(unittest.TestCase): def setUp(self): - self.s = univ.SequenceOf(componentType=univ.OctetString()) + self.s = univ.SetOf(componentType=univ.OctetString()) def __init(self): self.s.clear() @@ -383,29 +447,55 @@ class SetOfEncoderTestCase(unittest.TestCase): def testDefMode(self): self.__init() - assert encoder.encode(self.s) == ints2octs((48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + assert encoder.encode(self.s) == ints2octs((49, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) def testIndefMode(self): self.__init() assert encoder.encode( self.s, defMode=False - ) == ints2octs((48, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) def testDefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=True, maxChunkSize=4 - ) == ints2octs((48, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + ) == ints2octs((49, 19, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) def testIndefModeChunked(self): self.__init() assert encoder.encode( self.s, defMode=False, maxChunkSize=4 - ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) + ) == ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0)) class SequenceEncoderTestCase(unittest.TestCase): def setUp(self): + self.s = univ.Sequence() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testDefMode(self): + assert encoder.encode(self.s) == ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + + def testIndefMode(self): + assert encoder.encode( + self.s, defMode=False + ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + def testDefModeChunked(self): + assert encoder.encode( + self.s, defMode=True, maxChunkSize=4 + ) == ints2octs((48, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) + + def testIndefModeChunked(self): + assert encoder.encode( + self.s, defMode=False, maxChunkSize=4 + ) == ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + + +class SequenceEncoderWithSchemaTestCase(unittest.TestCase): + def setUp(self): self.s = univ.Sequence( componentType=namedtype.NamedTypes( namedtype.NamedType('place-holder', univ.Null()), @@ -530,6 +620,32 @@ class SequenceEncoderTestCase(unittest.TestCase): class SetEncoderTestCase(unittest.TestCase): def setUp(self): + self.s = univ.Set() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testDefMode(self): + assert encoder.encode(self.s) == ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)) + + def testIndefMode(self): + assert encoder.encode( + self.s, defMode=False + ) == ints2octs((49, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + def testDefModeChunked(self): + assert encoder.encode( + self.s, defMode=True, maxChunkSize=4 + ) == ints2octs((49, 24, 5, 0, 36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 2, 1, 1)) + + def testIndefModeChunked(self): + assert encoder.encode( + self.s, defMode=False, maxChunkSize=4 + ) == ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)) + + +class SetEncoderWithSchemaTestCase(unittest.TestCase): + def setUp(self): self.s = univ.Set( componentType=namedtype.NamedTypes( namedtype.NamedType('place-holder', univ.Null()), @@ -652,6 +768,49 @@ class SetEncoderTestCase(unittest.TestCase): class ChoiceEncoderTestCase(unittest.TestCase): + + def testEmpty(self): + s = univ.Choice() + try: + encoder.encode(s) + except PyAsn1Error: + pass + else: + assert 0, 'encoded unset choice' + + def testDefModeOptionOne(self): + s = univ.Choice() + s.setComponentByPosition(0, univ.Null('')) + assert encoder.encode(s) == ints2octs((5, 0)) + + def testDefModeOptionTwo(self): + s = univ.Choice() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode(s) == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + + def testIndefMode(self): + s = univ.Choice() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=False + ) == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)) + + def testDefModeChunked(self): + s = univ.Choice() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=True, maxChunkSize=4 + ) == ints2octs((36, 17, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110)) + + def testIndefModeChunked(self): + s = univ.Choice() + s.setComponentByPosition(0, univ.OctetString('quick brown')) + assert encoder.encode( + s, defMode=False, maxChunkSize=4 + ) == ints2octs((36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0)) + + +class ChoiceEncoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.Choice( componentType=namedtype.NamedTypes( diff --git a/tests/codec/cer/test_encoder.py b/tests/codec/cer/test_encoder.py index a1419fd..7b0cc8c 100644 --- a/tests/codec/cer/test_encoder.py +++ b/tests/codec/cer/test_encoder.py @@ -46,74 +46,6 @@ class OctetStringEncoderTestCase(unittest.TestCase): ) == ints2octs((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0)) -class SetEncoderTestCase(unittest.TestCase): - def setUp(self): - self.s = univ.Set(componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null('')), - namedtype.OptionalNamedType('first-name', univ.OctetString()), - namedtype.DefaultedNamedType('age', univ.Integer(33)) - )) - - def __init(self): - self.s.clear() - self.s.setComponentByPosition(0) - - def __initWithOptional(self): - self.s.clear() - self.s.setComponentByPosition(0) - self.s.setComponentByPosition(1, 'quick brown') - - def __initWithDefaulted(self): - self.s.clear() - self.s.setComponentByPosition(0) - self.s.setComponentByPosition(2, 1) - - def __initWithOptionalAndDefaulted(self): - self.s.clear() - self.s.setComponentByPosition(0, univ.Null('')) - self.s.setComponentByPosition(1, univ.OctetString('quick brown')) - self.s.setComponentByPosition(2, univ.Integer(1)) - - def testIndefMode(self): - self.__init() - assert encoder.encode(self.s) == ints2octs((49, 128, 5, 0, 0, 0)) - - def testWithOptionalIndefMode(self): - self.__initWithOptional() - assert encoder.encode( - self.s - ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) - - def testWithDefaultedIndefMode(self): - self.__initWithDefaulted() - assert encoder.encode( - self.s - ) == ints2octs((49, 128, 2, 1, 1, 5, 0, 0, 0)) - - def testWithOptionalAndDefaultedIndefMode(self): - self.__initWithOptionalAndDefaulted() - assert encoder.encode( - self.s - ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) - - -class SetWithChoiceEncoderTestCase(unittest.TestCase): - def setUp(self): - c = univ.Choice(componentType=namedtype.NamedTypes( - namedtype.NamedType('actual', univ.Boolean(0)) - )) - self.s = univ.Set(componentType=namedtype.NamedTypes( - namedtype.NamedType('place-holder', univ.Null('')), - namedtype.NamedType('status', c) - )) - - def testIndefMode(self): - self.s.setComponentByPosition(0) - self.s.setComponentByName('status') - self.s.getComponentByName('status').setComponentByPosition(0, 1) - assert encoder.encode(self.s) == ints2octs((49, 128, 1, 1, 255, 5, 0, 0, 0)) - - class GeneralizedTimeEncoderTestCase(unittest.TestCase): # def testExtraZeroInSeconds(self): # try: @@ -214,10 +146,107 @@ class UTCTimeEncoderTestCase(unittest.TestCase): ) == ints2octs((23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90)) +class SequenceOfEncoderTestCase(unittest.TestCase): + def testEmpty(self): + s = univ.SequenceOf() + assert encoder.encode(s) == ints2octs((48, 128, 0, 0)) + + def testDefMode1(self): + s = univ.SequenceOf() + s.append(univ.OctetString('a')) + s.append(univ.OctetString('ab')) + assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + + def testDefMode2(self): + s = univ.SequenceOf() + s.append(univ.OctetString('ab')) + s.append(univ.OctetString('a')) + assert encoder.encode(s) == ints2octs((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0)) + + def testDefMode3(self): + s = univ.SequenceOf() + s.append(univ.OctetString('b')) + s.append(univ.OctetString('a')) + assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 98, 4, 1, 97, 0, 0)) + + def testDefMode4(self): + s = univ.SequenceOf() + s.append(univ.OctetString('a')) + s.append(univ.OctetString('b')) + assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + + +class SequenceOfEncoderWithSchemaTestCase(unittest.TestCase): + def setUp(self): + self.s = univ.SequenceOf(componentType=univ.OctetString()) + + def testEmpty(self): + self.s.clear() + assert encoder.encode(self.s) == ints2octs((48, 128, 0, 0)) + + def testIndefMode1(self): + self.s.clear() + self.s.append('a') + self.s.append('ab') + assert encoder.encode(self.s) == ints2octs((48, 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((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0)) + + def testIndefMode3(self): + self.s.clear() + self.s.append('b') + self.s.append('a') + assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 98, 4, 1, 97, 0, 0)) + + def testIndefMode4(self): + self.s.clear() + self.s.append('a') + self.s.append('b') + assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + + class SetOfEncoderTestCase(unittest.TestCase): + def testEmpty(self): + s = univ.SetOf() + assert encoder.encode(s) == ints2octs((49, 128, 0, 0)) + + def testDefMode1(self): + s = univ.SetOf() + s.append(univ.OctetString('a')) + s.append(univ.OctetString('ab')) + assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + + def testDefMode2(self): + s = univ.SetOf() + s.append(univ.OctetString('ab')) + s.append(univ.OctetString('a')) + assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 2, 97, 98, 0, 0)) + + def testDefMode3(self): + s = univ.SetOf() + s.append(univ.OctetString('b')) + s.append(univ.OctetString('a')) + assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + + def testDefMode4(self): + s = univ.SetOf() + s.append(univ.OctetString('a')) + s.append(univ.OctetString('b')) + assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) + + +class SetOfEncoderWithSchemaTestCase(unittest.TestCase): def setUp(self): self.s = univ.SetOf(componentType=univ.OctetString()) + def testEmpty(self): + self.s.clear() + assert encoder.encode(self.s) == ints2octs((49, 128, 0, 0)) + def testIndefMode1(self): self.s.clear() self.s.append('a') @@ -247,6 +276,205 @@ class SetOfEncoderTestCase(unittest.TestCase): assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0)) +class SetEncoderTestCase(unittest.TestCase): + def setUp(self): + self.s = univ.Set() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testIndefMode(self): + assert encoder.encode(self.s) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithOptionalIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithDefaultedIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithOptionalAndDefaultedIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + +class SetEncoderWithSchemaTestCase(unittest.TestCase): + def setUp(self): + self.s = univ.Set(componentType=namedtype.NamedTypes( + namedtype.NamedType('place-holder', univ.Null('')), + namedtype.OptionalNamedType('first-name', univ.OctetString()), + namedtype.DefaultedNamedType('age', univ.Integer(33)) + )) + + def __init(self): + self.s.clear() + self.s.setComponentByPosition(0) + + def __initWithOptional(self): + self.s.clear() + self.s.setComponentByPosition(0) + self.s.setComponentByPosition(1, 'quick brown') + + def __initWithDefaulted(self): + self.s.clear() + self.s.setComponentByPosition(0) + self.s.setComponentByPosition(2, 1) + + def __initWithOptionalAndDefaulted(self): + self.s.clear() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testIndefMode(self): + self.__init() + assert encoder.encode(self.s) == ints2octs((49, 128, 5, 0, 0, 0)) + + def testWithOptionalIndefMode(self): + self.__initWithOptional() + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithDefaultedIndefMode(self): + self.__initWithDefaulted() + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 5, 0, 0, 0)) + + def testWithOptionalAndDefaultedIndefMode(self): + self.__initWithOptionalAndDefaulted() + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + +class SetWithChoiceWithSchemaEncoderTestCase(unittest.TestCase): + def setUp(self): + c = univ.Choice(componentType=namedtype.NamedTypes( + namedtype.NamedType('actual', univ.Boolean(0)) + )) + self.s = univ.Set(componentType=namedtype.NamedTypes( + namedtype.NamedType('place-holder', univ.Null('')), + namedtype.NamedType('status', c) + )) + + def testIndefMode(self): + self.s.setComponentByPosition(0) + self.s.setComponentByName('status') + self.s.getComponentByName('status').setComponentByPosition(0, 1) + assert encoder.encode(self.s) == ints2octs((49, 128, 1, 1, 255, 5, 0, 0, 0)) + + +class SetEncoderTestCase(unittest.TestCase): + def setUp(self): + self.s = univ.Set() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testIndefMode(self): + assert encoder.encode(self.s) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithOptionalIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithDefaultedIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + def testWithOptionalAndDefaultedIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0)) + + +class SequenceEncoderTestCase(unittest.TestCase): + def setUp(self): + self.s = univ.Sequence() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testIndefMode(self): + assert encoder.encode(self.s) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + def testWithOptionalIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + def testWithDefaultedIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + def testWithOptionalAndDefaultedIndefMode(self): + assert encoder.encode( + self.s + ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + +class SequenceEncoderWithSchemaTestCase(unittest.TestCase): + def setUp(self): + self.s = univ.Sequence( + componentType=namedtype.NamedTypes( + namedtype.NamedType('place-holder', univ.Null('')), + namedtype.OptionalNamedType('first-name', univ.OctetString()), + namedtype.DefaultedNamedType('age', univ.Integer(33)) + ) + ) + + def __init(self): + self.s.clear() + self.s.setComponentByPosition(0) + + def __initWithOptional(self): + self.s.clear() + self.s.setComponentByPosition(0) + self.s.setComponentByPosition(1, 'quick brown') + + def __initWithDefaulted(self): + self.s.clear() + self.s.setComponentByPosition(0) + self.s.setComponentByPosition(2, 1) + + def __initWithOptionalAndDefaulted(self): + self.s.clear() + self.s.setComponentByPosition(0, univ.Null('')) + self.s.setComponentByPosition(1, univ.OctetString('quick brown')) + self.s.setComponentByPosition(2, univ.Integer(1)) + + def testIndefMode(self): + self.__init() + assert encoder.encode(self.s) == ints2octs((48, 128, 5, 0, 0, 0)) + + def testWithOptionalIndefMode(self): + self.__initWithOptional() + assert encoder.encode( + self.s + ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0)) + + def testWithDefaultedIndefMode(self): + self.__initWithDefaulted() + assert encoder.encode( + self.s + ) == ints2octs((48, 128, 5, 0, 2, 1, 1, 0, 0)) + + def testWithOptionalAndDefaultedIndefMode(self): + self.__initWithOptionalAndDefaulted() + assert encoder.encode( + self.s + ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0)) + + class NestedOptionalSequenceEncoderTestCase(unittest.TestCase): def setUp(self): inner = univ.Sequence( |