How to use the asn1tools.compile_string function in asn1tools

To help you get started, we’ve selected a few asn1tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eerimoq / asn1tools / tests / test_uper.py View on Github external
def test_bmp_string(self):
        foo = asn1tools.compile_string(
            "Foo DEFINITIONS AUTOMATIC TAGS ::= "
            "BEGIN "
            "A ::= BMPString "
            "B ::= SEQUENCE { "
            "  a BOOLEAN, "
            "  b BMPString "
            "} "
            "C ::= SEQUENCE { "
            "  a BMPString (SIZE(1..128)), "
            "  b BMPString (SIZE(1..256)) "
            "} "
            "END",
            'uper')

        datas = [
            ('A',                      '', b'\x00'),
github eerimoq / asn1tools / tests / test_uper.py View on Github external
def test_bit_string(self):
        foo = asn1tools.compile_string(
            "Foo DEFINITIONS AUTOMATIC TAGS ::= "
            "BEGIN "
            "A ::= BIT STRING "
            "B ::= BIT STRING (SIZE (9)) "
            "C ::= BIT STRING (SIZE (5..7)) "
            "D ::= SEQUENCE { "
            "  a BOOLEAN, "
            "  b BIT STRING "
            "} "
            "E ::= BIT STRING { "
            "  a (0), "
            "  b (1), "
            "  c (2) "
            "} "
            "F ::= SEQUENCE { "
            "  a BIT STRING, "
github eerimoq / asn1tools / tests / test_uper.py View on Github external
def test_error_out_of_data(self):
        foo = asn1tools.compile_string(
            "Foo DEFINITIONS AUTOMATIC TAGS ::= "
            "BEGIN "
            "A ::= INTEGER "
            "B ::= SEQUENCE { "
            "  a SEQUENCE { "
            "    b BOOLEAN, "
            "    c INTEGER "
            "  } "
            "} "
            "END",
            'uper')

        datas = [
            ('A', b'',         'out of data at bit offset 0 (0.0 bytes)'),
            ('B', b'\x00',     'a: c: out of data at bit offset 1 (0.1 bytes)'),
            ('B', b'\x80\x80', 'a: c: out of data at bit offset 9 (1.1 bytes)')
github eerimoq / asn1tools / tests / test_codecs_consistency.py View on Github external
def decode_codecs(self, type_spec, decoded, encoded):
        spec = (
            "Foo DEFINITIONS AUTOMATIC TAGS ::= "
            "BEGIN "
            "A ::= " + type_spec + " "
            + "END"
        )

        for codec, encoded_message in zip(CODECS, encoded):
            foo = asn1tools.compile_string(spec, codec)
            decoded_message = foo.decode('A',
                                         encoded_message,
                                         check_constraints=True)
            self.assertEqual(decoded_message, decoded)
github eerimoq / asn1tools / tests / test_c_source.py View on Github external
def test_compile_error_members_backtrace(self):
        for codec, module in CODECS_AND_MODULES:
            foo = asn1tools.compile_string(
                'Foo DEFINITIONS AUTOMATIC TAGS ::= BEGIN '
                '    A ::= SEQUENCE { '
                '        a CHOICE { '
                '            b INTEGER '
                '        } '
                '    } '
                'END',
                codec)

            with self.assertRaises(asn1tools.errors.Error) as cm:
                module.generate(foo, 'foo')

            self.assertEqual(str(cm.exception),
                             "Foo.A.a.b: INTEGER has no minimum value.")
github eerimoq / asn1tools / tests / test_jer.py View on Github external
def test_sequence_of(self):
        foo = asn1tools.compile_string(
            "Foo DEFINITIONS ::= "
            "BEGIN "
            "A ::= SEQUENCE OF INTEGER "
            "END",
            'jer')

        datas = [
            ('A',     [], b'[]'),
            ('A', [1, 3], b'[1, 3]')
        ]

        for type_name, decoded, encoded in datas:
            self.assert_encode_decode_string(foo, type_name, decoded, encoded)
github eerimoq / asn1tools / tests / test_jer.py View on Github external
def test_generalized_time(self):
        foo = asn1tools.compile_string(
            "Foo DEFINITIONS ::= "
            "BEGIN "
            "A ::= GeneralizedTime "
            "END",
            'jer')

        datas = [
            ('A', gt2dt('20001231235959.999'), b'"20001231235959.999"')
        ]

        for type_name, decoded, encoded in datas:
            self.assert_encode_decode_string(foo, type_name, decoded, encoded)
github eerimoq / asn1tools / tests / test_c_source.py View on Github external
def test_compile_error_integer_no_minimum(self):
        for codec, module in CODECS_AND_MODULES:
            foo = asn1tools.compile_string(
                'Foo DEFINITIONS AUTOMATIC TAGS ::= BEGIN '
                '    A ::= INTEGER (MIN..10) '
                'END',
                codec)

            with self.assertRaises(asn1tools.errors.Error) as cm:
                module.generate(foo, 'foo')

            self.assertEqual(str(cm.exception),
                             "Foo.A: INTEGER has no minimum value.")
github eerimoq / asn1tools / tests / test_xer.py View on Github external
def test_sequence_of(self):
        foo = asn1tools.compile_string(
            "Foo DEFINITIONS AUTOMATIC TAGS ::= "
            "BEGIN "
            "A ::= SEQUENCE OF INTEGER "
            "B ::= SEQUENCE OF A "
            "C ::= SEQUENCE OF BOOLEAN "
            "D ::= SEQUENCE OF E "
            "E ::= BOOLEAN "
            "F ::= SEQUENCE OF CHOICE { a BOOLEAN, b INTEGER } "
            "G ::= SEQUENCE OF ENUMERATED { one } "
            "H ::= SEQUENCE OF SEQUENCE { a INTEGER } "
            "I ::= SEQUENCE OF BIT STRING "
            "J ::= SEQUENCE OF OCTET STRING "
            "K ::= SEQUENCE OF OBJECT IDENTIFIER "
            "L ::= SEQUENCE OF SEQUENCE OF NULL "
            "M ::= SEQUENCE OF SET OF NULL "
            "END",
github eerimoq / asn1tools / examples / benchmarks / codecs.py View on Github external
def encode_decode(codec):
    spec = asn1tools.compile_string(
        'Ber DEFINITIONS ::= BEGIN '
        '  A ::= SEQUENCE { '
        '    a BOOLEAN, '
        '    b INTEGER, '
#        '    c REAL, '
        '    d NULL, '
        '    e BIT STRING, '
        '    f OCTET STRING, '
        '    g OBJECT IDENTIFIER, '
        '    h ENUMERATED {a, b}, '
        '    i SEQUENCE {}, '
        '    j SEQUENCE OF NULL, '
        '    k SET {}, '
        '    l SET OF NULL, '
        '    m CHOICE {a NULL}, '
        '    n UTF8String, '