How to use the asn1tools.parse_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_parse.py View on Github external
def test_parse_error_missing_type(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= BEGIN '
                                   'B ::= '
                                   'END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 1, column 31: 'A DEFINITIONS ::= BEGIN "
            "B ::= >!
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_late_extension_additions(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= BEGIN '
                                   'Foo ::= SEQUENCE { '
                                   'a BOOLEAN, '
                                   '..., '
                                   '..., '
                                   '[[ '
                                   'c BOOLEAN '
                                   ']] '
                                   '} '
                                   'END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 1, column 63: \'A DEFINITIONS ::= "
            "BEGIN Foo ::= SEQUENCE { a BOOLEAN, ..., ...>!<, [[ c BOOLEAN ]] "
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_type_assignment_missing_assignment(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= BEGIN A END')

        self.assertEqual(str(cm.exception),
                         "Invalid ASN.1 syntax at line 1, column 27: "
                         "'A DEFINITIONS ::= BEGIN A >!
github eerimoq / asn1tools / tests / test_type_checker.py View on Github external
def assert_good_bad(self,
                        type_spec,
                        expected_type_string,
                        good_datas,
                        bad_datas,
                        bad_datas_strings=None):
        foo = asn1tools.parse_string(
            "Foo DEFINITIONS AUTOMATIC TAGS ::= "
            "BEGIN "
            "A ::= " + type_spec + " "
            "END")

        foo = asn1tools.codecs.type_checker.compile_dict(foo)

        for data in good_datas:
            foo['Foo']['A'].encode(data)

        if bad_datas_strings is None:
            bad_datas_strings = [str(data) for data in bad_datas]

        for data, bad_datas_string in zip(bad_datas, bad_datas_strings):
            with self.assertRaises(asn1tools.EncodeError) as cm:
                foo['Foo']['A'].encode(data)
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_definitive_identifier(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A {} DEFINITIONS ::= BEGIN '
                                   'END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 1, column 4: 'A {>!<} DEFINITIONS "
            "::= BEGIN END': Expected {{identifier Suppress:(\"(\") - "
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_size_constraint_missing_parentheses(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= BEGIN '
                                   'B ::= INTEGER (SIZE 1)'
                                   'END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 1, column 45: \'A DEFINITIONS ::= "
            "BEGIN B ::= INTEGER (SIZE >!<1)END\': Expected \"(\".")
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_sequence_missing_member_name(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= BEGIN'
                                   '  A ::= SEQUENCE { A } '
                                   'END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 1, column 43: 'A DEFINITIONS ::= "
            "BEGIN  A ::= SEQUENCE { >!
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_sequence_missing_type(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= BEGIN'
                                   '  A ::= SEQUENCE { a } '
                                   'END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 1, column 45: 'A DEFINITIONS ::= BEGIN "
            " A ::= SEQUENCE { a >!<} END': Expected Type.")
github eerimoq / asn1tools / tests / test_parse.py View on Github external
def test_parse_error_missing_single_line_comment_end(self):
        with self.assertRaises(asn1tools.ParseError) as cm:
            asn1tools.parse_string('A DEFINITIONS ::= \n'
                                   'BEGIN -- END')

        self.assertEqual(
            str(cm.exception),
            "Invalid ASN.1 syntax at line 2, column 7: 'BEGIN >!<-- END': "
            "Missing newline or -- for single line comment.")