libmich
libmich copied to clipboard
add a _DISPLAY_LABEL option in order to choose displaying ASN1 code or associated label
Hi,
I needed to display ASN1 codes while decoding PER ASN1 data.
I provide you the code I change in your library in order to make that to work.
Best regards,
Jérôme
Hello, thank you for your submission. However, changing the type of data put in the _val attribute will certainly break any re-encoding of those values (see the docstrings of the ASN1Obj class in asn1/ASN1.py). Did you run the ASN.1 tests (in asn1/test.py) successfully after your changes ? Best Regards Benoit
Hello,
I run test.py and it works.... but I have not set _DISPLAY_LABEL (my new options) to False.
I think, that if I set _DISPLAY_LABEL to False, the re-encoding will not work. Do you think I have to adapt that ? (that's not usefull in my case).
Yes, this actually breaks the re-encoding when decoding is done with PER._DISPLAY_LABEL set to False. There is several possibilities to make is work properly:
- the cleanest would be to make specific repr() cases in ASN1Obj (ASN1.py), for ENUMERATED and CHOICE, so that the type of value associated with those objects is not changed, but when you print() the object within Python, you can have the label or the index.
- another clean solution without touching the repr() method in ASN1Obj would be to create a get_index() method returning your required info specifically.
- a less clean, but working solution, would be to patch the encoding methods in PER: encode_enum() and encode_choice(), to take this _DISPLAY_LABEL attribute into account.
Best Regards, Benoit
Hello,
I need the ASN1 code not only for displaying purpose, but also to use these codes directly in the decoded object. So, I'm thinking of implementing the option number 3. The one you qualify of "less cleaner".
Is that ok with you ?
Yes !
Le jeudi 17 novembre 2016, Jérôme BAROTIN [email protected] a écrit :
Hello,
I need the ASN1 code not only for displaying purpose, but also to use these codes directly in the decoded object. So, I thinking of implementing the option number 3. The one you qualify of "less cleaner".
Is that ok with you ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mitshell/libmich/pull/16#issuecomment-261296699, or mute the thread https://github.com/notifications/unsubscribe-auth/AA9wHwUDPG1nP6YXxIojE2wmIiNroMN0ks5q_IIBgaJpZM4Knb5x .