libmich icon indicating copy to clipboard operation
libmich copied to clipboard

add a _DISPLAY_LABEL option in order to choose displaying ASN1 code or associated label

Open jbarotin opened this issue 8 years ago • 5 comments

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

jbarotin avatar Nov 02 '16 16:11 jbarotin

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

mitshell avatar Nov 02 '16 23:11 mitshell

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).

jbarotin avatar Nov 03 '16 08:11 jbarotin

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:

  1. 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.
  2. another clean solution without touching the repr() method in ASN1Obj would be to create a get_index() method returning your required info specifically.
  3. 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

mitshell avatar Nov 04 '16 17:11 mitshell

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 ?

jbarotin avatar Nov 17 '16 16:11 jbarotin

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 .

mitshell avatar Nov 17 '16 21:11 mitshell