Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 ::= >!
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 ]] "
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 >!
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)
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:(\"(\") - "
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 \"(\".")
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 { >!
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.")
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.")