Skip to content

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

Open
jbarotin wants to merge 1 commit into
mitshell:masterfrom
jbarotin:master
Open

add a _DISPLAY_LABEL option in order to choose displaying ASN1 code or associated label#16
jbarotin wants to merge 1 commit into
mitshell:masterfrom
jbarotin:master

Conversation

@jbarotin

@jbarotin jbarotin commented Nov 2, 2016

Copy link
Copy Markdown

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

ASN1 code in order to string label for enum and choice type
@jbarotin jbarotin changed the title add a _DISPLAY_LABEL option in order to choose displaying add a _DISPLAY_LABEL option in order to choose displaying ASN1 code or associated label Nov 2, 2016
@mitshell

mitshell commented Nov 2, 2016

Copy link
Copy Markdown
Owner

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

@jbarotin

jbarotin commented Nov 3, 2016

Copy link
Copy Markdown
Author

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

@mitshell

mitshell commented Nov 4, 2016

Copy link
Copy Markdown
Owner

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

@jbarotin

jbarotin commented Nov 17, 2016

Copy link
Copy Markdown
Author

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 ?

@mitshell

Copy link
Copy Markdown
Owner

Yes !

Le jeudi 17 novembre 2016, Jérôme BAROTIN notifications@github.com 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
#16 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA9wHwUDPG1nP6YXxIojE2wmIiNroMN0ks5q_IIBgaJpZM4Knb5x
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants