Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Decoding into a local rather than a global object #26

Open
ibookstein opened this issue Aug 21, 2018 · 1 comment
Open

Decoding into a local rather than a global object #26

ibookstein opened this issue Aug 21, 2018 · 1 comment

Comments

@ibookstein
Copy link

I've poked around a bit and read the documentation, and had a question regarding best-practice usage.
The documentation's example for decoding a buffer into an ASN.1 object decodes the buffer into a global instance of a constructed type. This is a global that is mutated for the entire application. Is there a correct/documented way wherein I could decode my data into a private, local instance of the desired type, rather than mutating global state? A simple attempt involving copy.deepcopy seemed to work, but I don't know if that's a good idea or not. The clone method I saw for some types in the repository isn't present on the compiled types.

@mitshell
Copy link
Contributor

You are experiencing a limitation of the ASN.1 runtime (see https://github.com/ANSSI-FR/pycrate/wiki/Compiling-asn1-specifications#limitations, last bullet). Duplicating locally each ASN.1 structures when we want to encode or decode a value would be costly, hence the use of global objects, which _val attribute gets written / read by the application.
Also, I did not write a clone method because of the complexity involved for large objects.
Using deepcopy seems a way (the only easy one ?) to handle this object structure duplication. If you come with a stable and efficient solution, feel free to propose an extension to the current code and documentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants