kimgr / asn1ate

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

Add --include-asn1 switch to pyasn1gen.py #65

Closed kimgr closed 5 years ago

kimgr commented 6 years ago

This embeds the ASN.1 source into the generated Python code.

Since a Python file can contain multiple ASN.1 modules, the ASN1_SOURCES constant is always a dict, and sources are keyed by ASN.1 module name.

kimgr commented 5 years ago

I pushed some fixups and a test case (that's not strictly used for --include-asn1, but handy nonetheless).

But I just realized that we're not including the source text -- only a regeneration of it from asn1ate's point of view. That is, str(module) regenerates a source document back from the semantic model. I don't know if that's a problem or not, but it might be an advantage, to be able to see how asn1ate sees the document. Splitting the source text into distinct modules seems like a bigger job at the moment.

rtweeks commented 5 years ago

I think it's fine to use the regenerated version, so long as it is semantically the same. The real point is to allow the python code to share the format of the data it understands in ASN.1 for language independence -- i.e. so additional tools can be written in other languages to use the same binary representation (especially in DER).

This is critical for my application (of ASN.1, actually a tool/library), because I use ASN.1 DER to express JSON-type data in a reproducible binary format feeding a SHA256 hash computation, the output of which is used as a table key in persistent data. If tools written in other languages want to compute the key natively from the JSON data to do lookups in that table, they need the ASN.1 to build their own binary format encoder. As an example, I could imagine another developer wanting to write a library in Haskell similar to the one I've written in Python; with my Python tool able to spit out the ASN.1, that developer doesn't have to dig in my repository for the ASN.1 (more important if it is otherwise proprietary), and this feature allows me to accomplish that without the gyrations necessary to include and read a non-Python file in my package.

On Fri, Jun 7, 2019, 2:58 AM Kim Gräsman notifications@github.com wrote:

I pushed some fixups and a test case (that's not strictly used for --include-asn1, but handy nonetheless).

But I just realized that we're not including the source text -- only a regeneration of it from asn1ate's point of view. That is, str(module) regenerates a source document back from the semantic model. I don't know if that's a problem or not, but it might be an advantage, to be able to see how asn1ate sees the document. Splitting the source text into distinct modules seems like a bigger job at the moment.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kimgr/asn1ate/pull/65?email_source=notifications&email_token=ABH34FJCZXFD6WTZCPDQNPDPZIWNNA5CNFSM4E7R4YS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXFMPAQ#issuecomment-499828610, or mute the thread https://github.com/notifications/unsubscribe-auth/ABH34FJO74YLWI7VWZ74IATPZIWNNANCNFSM4E7R4YSQ .

kimgr commented 5 years ago

Thanks for the background and confirmation that this is good enough. Merging now.