kimgr / asn1ate

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

pyasn1gen.py parsing fails #19

Open hillfolk opened 9 years ago

hillfolk commented 9 years ago

Hello, I am trying to use your library to generate pyasn1 file from this ASN

http://hillfolk.synology.me:5000/fbsharing/F6Y9Fv87

but errors are displayed.

  File "asn1ate/asn1ate/pyasn1gen.py", line 589, in 
    sys.exit(main(sys.argv[1:]))
  File "asn1ate/asn1ate/pyasn1gen.py", line 575, in main
    parse_tree = parser.parse_asn1(asn1def)
  File "/home/junyong/Source/ASN-Test/venv/local/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1
    parse_result = grammar.parseString(asn1_definition)
  File "/home/junyong/Source/ASN-Test/venv/local/lib/python2.7/site-packages/pyparsing.py", line 1111, in parseString
    raise exc
pyparsing.ParseException: Expected "END" (at char 16673), (line:218, col:44)

Can I give you help me?

kimgr commented 9 years ago

Error reporting in asn1ate is terrible, but the line number usually gives a hint. Near line 218 I found this:

EndApplicationMessage ::= SEQUENCE {
    endApplication-Message-id           ISO14827-MESSAGE.&id,
    endApplication-Message-msg          ISO14827-MESSAGE.&MessageBody
}

The & syntax is not supported by the parser (yet), so if you can phrase that with simpler mechanisms, it might work.

Development of asn1ate is driven mostly by my own needs, so I might not get to this within any reasonable timeframe.

hillfolk commented 9 years ago

thank for answer. I have question. it is ASN.1 Information Objects (X.681) you have support plan?

GENERAL-PROCEDURE ::= CLASS {
&Message,
&Reply               OPTIONAL,
&Error               OPTIONAL,
&id          PrintableString UNIQUE }

I think this is a memory pointer. In Python, can I use it? Give me a little hint. I do not have good idea Sorry My English is not good enough.

I always thank you.

kimgr commented 9 years ago

I'd would like to support parsing all of ASN.1, and code-generation for elements that have a reasonable representation in pyasn1. But I realistically don't have time to work on more uncommon features unless I happen to need them for my own projects.

Patches are of course always welcome!

Maja46 commented 7 years ago

Hello, I wonder if I stumble on the same problem with "&", e.g. for DMI-EXTENSION .&id and DMI-EXTENSION .&Value in identifier DMI-EXTENSION .&id ( { , ...} ) ,

I got the task to build a decoder for PS CDR files according to the 3GPP specs Rel 10 and beyond. Therefore I downloaded from "http://www.3gpp.org/ftp/specs/archive/32_series/32.298/ASN.1/" one of their ASN compilations and tried to compile the files GenericChargingDataTypes.EXP or GPRSChargingDataTypes.EXP using asn1ate.py. 32298-e20 ASN1.zip

It always stops with error, e.g. python pyasn1gen.py "c:\Users\maja\32298-e20 ASN1\GPRSChargingDataTypes.EXP" Traceback (most recent call last): File "pyasn1gen.py", line 588, in sys.exit(main(sys.argv[1:])) File "pyasn1gen.py", line 574, in main parse_tree = parser.parse_asn1(asn1def) File "C:\Program Files\Python2.7.13\lib\site-packages\asn1ate\parser.py", line 40, in parse_asn1 parse_result = grammar.parseString(asn1_definition) File "C:\Program Files\Python2.7.13\lib\site-packages\pyparsing.py", line 1632 , in parseString raise exc pyparsing.ParseException: Expected "END" (at char 383), (line:13, col:23)

python pyasn1gen.py "c:\Users\maja\Test Automation\32298-e20 ASN1\GenericChargingDataTypes.EXP" Traceback (most recent call last): File "pyasn1gen.py", line 588, in sys.exit(main(sys.argv[1:])) File "pyasn1gen.py", line 574, in main parse_tree = parser.parse_asn1(asn1def) File "C:\Program Files\Python2.7.13\lib\site-packages\asn1ate\parser.py", line 40, in parse_asn1 parse_result = grammar.parseString(asn1_definition) File "C:\Program Files\Python2.7.13\lib\site-packages\pyparsing.py", line 1632 , in parseString raise exc pyparsing.ParseException: Expected "END" (at char 2170), (line:65, col:24)

I found in the testdata/public/ a Huawei CS CDR and thought/hoped that you found a way to compile the 3GPP ASN files for pyasn1.

Kind regards, Maja

kimgr commented 7 years ago

Hello Maja,

Unfortunately I still don't have support for the & syntax (and I don't yet understand what it's used for, and how it might translate into pyasn1.) I'm spending a couple of days working on asn1ate now, so I might get to this before the week is over.

The more you can tell me about the semantics of & and the expected output, the easier this will be for me.

The ASN.1 files under testdata/public are just examples I've found published on the web, and things that would be great if asn1ate could handle, e.g. LDAP, Kerberos, etc. I haven't had a chance to implement everything required for them yet.

etingof commented 7 years ago

Hi Kim,

Take a look at the RFC-6025 -- it's about how to convert X.680 syntax into X.208 one.

Just my 2c. ;)

kimgr commented 7 years ago

Thanks Ilya! Looks like there's a pretty simple mechanical translation from the fancy syntax.