kimgr / asn1ate

A Python library for translating ASN.1 into other forms.
Other
69 stars 41 forks source link

Failure parsing minimal example with VisibleString #56

Open rbdixon opened 7 years ago

rbdixon commented 7 years ago

This is valid according to ASN.1 Playground:

Test DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

UARFCN ::= INTEGER(0..16383)
FQDN ::= VisibleString(FROM ("a".."z" | "A".."Z" | "0".."9" | ".-")) (SIZE (1..255))

END

This is excerpted from Wireshark's ULP support.

The example above fails with:

Traceback (most recent call last):
  File "../.direnv/python-2.7.13/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 588, in <module>
    sys.exit(main(sys.argv[1:]))
  File "../.direnv/python-2.7.13/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 574, in main
    parse_tree = parser.parse_asn1(asn1def)
  File "/Users/rbdixon/projects/library/201708-vzw-lte_precloc/testing/fuzz/.direnv/python-2.7.13/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1
    parse_result = grammar.parseString(asn1_definition)
  File "/Users/rbdixon/projects/library/201708-vzw-lte_precloc/testing/fuzz/.direnv/python-2.7.13/lib/python2.7/site-packages/pyparsing.py", line 1632, in parseString
    raise exc
pyparsing.ParseException: Expected "END" (at char 94), (line:5, col:23)

I believe that VisibleString is supported since it is parsed correctly elsewhere in my ASN.1 example. Any advice on getting this going?

kimgr commented 7 years ago

Thanks for the report. I think the constraint is the problem in this case, there's definitely no support for FROM (which I think is a so-called alphabet constraint), but the SIZE might be accepted for VisibleString.

I don't think constraints make it through the encoding, so you could try removing the constraints and hope for the best.

rbdixon commented 7 years ago

This was my thought, too. I did some goofing around and this fails as well:

Test DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

FQDN ::= VisibleString() (SIZE (1..255))

END

I'll noodle around on this a bit. Just thought I'd bring it up in case there was an obvious issue.

rbdixon commented 7 years ago

Actually... when I turn the brain on:

Test DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

FQDN ::= VisibleString(SIZE (1..255))

END

This works. Let me give this a whirl.