P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
381 stars 132 forks source link

argument of type 'NoneType' is not iterable #166

Closed igrag closed 2 years ago

igrag commented 2 years ago

Hello, I am trying to compile the IS TS 103 301 from ETSI (https://forge.etsi.org/rep/ITS/asn1/is_ts103301). These are the asn files for the IVI messages. I am getting the folllowing error:

Exception has occurred: TypeError argument of type 'NoneType' is not iterable File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 4337, in __parse_const_withcomps_comp if ident not in cont: File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 4284, in _parse_const_withcomps self.parse_const_withcomps_comp(rc, const_comp) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 3976, in _parse_const self._parse_const_withcomps(const) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 1716, in parse_def rest = self._parse_const(text) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 3418, in __parse_cont_comps comp_t = Comp.parse_def(comp_t) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 3387, in _parse_cont_seq self.__parse_cont_comps(text_comps, self._type, False) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 2269, in _parse_cont text = getattr(self, self._PARSE_CONT_DISPATCH[self._type])(text) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 1705, in parse_def text = self._parse_cont(text) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asn_obj.py", line 3198, in _parse_cont_seqof text = Comp.parse_def(text) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 2269, in _parse_cont text = getattr(self, self._PARSE_CONT_DISPATCH[self._type])(text) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnobj.py", line 1705, in parse_def text = self._parse_cont(text) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnproc.py", line 879, in asnobj_compile text = Obj.parse_def(Obj._text_def) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnproc.py", line 945, in compile_modules ObjNew = asnobj_compile(Obj) File "/home/grag/work/opt-unex-software/pycrate/pycrate_asn1c/asnproc.py", line 257, in compile_text compile_modules(remain) File "/home/grag/work/opt-unex-software/pycrate/tools/pycrate_asn1compile.py", line 219, in main compile_text(txt, ckw) File "/home/grag/work/opt-unex-software/pycrate/tools/pycrateasn1compile.py", line 267, in sys.exit(main())**

I think that the error occurs in the following statement in one of the asn files:

GetInstanceRs{Container}::= SEQUENCE (SIZE (0..127,...)) OF SEQUENCE { attributeId INTEGER(0..127,...), -- number of instances retrieved attributeValues Container (WITH COMPONENTS {octetstring PRESENT}) -- The octetstring shall contain the contatenation of -- the unaligned PER encodings of the values of the -- instances, with each encoding padded to an integral -- of octets as specified for a top-level type in -- ISO/IEC 8825-2 }

If I comment out this then the compilation completes successfully. Is this a limitation of pycrate or a problem in the asn file?

Best Regards, Giannis

p1-bmu commented 2 years ago

Thanks for reporting. This may correspond to an issue in the compiler, or in the spec.

Regarding this ETSI IS specification, it relies on an ISO TS 19321 standard which is not free, and not part of the ETSI git repository. Hopefully, one can access the ASN.1 modules here: https://standards.iso.org/iso/ts/19321/. But then, this last one requires the module CITSdataDictionary1 {iso(1) standard(0) cits-applMgmt (17419) dataDictionary (1) version1 (1)}, which I cannot find on the ISO website (looking at https://standards.iso.org/iso/ts/17419/).

So, unless you provide the full ASN.1 specification for the compilation to work, I won't be able to reproduce.

igrag commented 2 years ago

Hello, Thank you for the answer and your help. Attached are the asn files that I have used.

Best Regards Giannis Gkragkopoulos

On Tue, Dec 14, 2021 at 11:15 AM Benoit Michau @.***> wrote:

Thanks for reporting. This may correspond to an issue in the compiler, or in the spec.

Regarding this ETSI IS specification, it relies on an ISO TS 19321 standard which is not free, and not part of the ETSI git repository. Hopefully, one can access the ASN.1 modules here: https://standards.iso.org/iso/ts/19321/. But then, this last one requires the module CITSdataDictionary1 {iso(1) standard(0) cits-applMgmt (17419) dataDictionary (1) version1 (1)}, which I cannot find on the ISO website (looking at https://standards.iso.org/iso/ts/17419/).

So, unless you provide the full ASN.1 specification for the compilation to work, I won't be able to reproduce.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/P1sec/pycrate/issues/166#issuecomment-993332782, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMDEX2BV2JHO5HCTLEBBDE3UQ4DMXANCNFSM5J52RYQQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ETSI_ITS_IS_TS103301_ORIGINAL.zip

p1-bmu commented 2 years ago

The attached set of asn1 files does not have any CITSdataDictionary1 module, unfortunately.

igrag commented 2 years ago

I am sorry. I uploaded wrong files Please use these. Thank you ETSI_ITS_IS_TS103301_ORIGINAL_NEW.zip .

p1-bmu commented 2 years ago

This one is also missing the CITSdataDictionary1 module.

igrag commented 2 years ago

Hi, in which file? I searched all the files in ETSI_ITS_IS_TS103301_ORIGINAL_NEW.zip and there is no CITSdataDictionary1 string anywhere.

p1-bmu commented 2 years ago

I fixed the compiler to bypass the processing of WITH COMPONENTS constraints in case of parameterization, which avoids the error. On the other side, we are still missing CITSdataDictionary1, as used in the IVI.asn file.

Actually, in your module, you have this in IVI.asn:

VarLengthNumber
FROM CITSapplMgmtIDs {iso(1) standard(0) cits-applMgmt (17419) dataDictionary (1) version1 (1)} 

Which is fine, so the module can compile fine.

Do you want me to introduce it into the library, together with other ITS modules ?

igrag commented 2 years ago

Thank you. I have no problem to include it in the library with the other standards. I have't tested anything yet, so I don't know if it actually works. I took the files from here: https://forge.etsi.org/rep/ITS/asn1. Although we are members of ETSI I didn't use my credentials so I think that all the ASNs are open.

Thanks again for your time and effort.

p1-bmu commented 2 years ago

OK, done. Now available as: from pycrate_asn1dir import ITS_IS.