Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to return Enveloped data as bytes as well as strings. #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

parneshraniga
Copy link
Contributor

This is useful in python 3 where strings are unicode. Current implementation is more pythonic and also relies on the flags to return appropriate data type from decryption of enveloped data.

…is is useful in python 3 where strings are unicode. Current implementation is more pythonic and also relies on the flags to return appropriate data type from decryption of enveloped data.
@vbwagner
Copy link
Owner

vbwagner commented Sep 5, 2019

It' s nice. I'm not sure that I would merge it as is, because this would cause incompatibile behavoir in python2 and python3 but it is definitely right way to go.

@parneshraniga
Copy link
Contributor Author

Although I haven't tested in py2 yet, I don't know if it will cause incompatible behaviour as bytes == str in py2. So under py2 you will get a str regardless of whether you set the binary flag or not. This should not interfere with any code.

I will try and put together some tests next week and see how I go.

@vbwagner
Copy link
Owner

vbwagner commented Sep 5, 2019

Look into ctypescrypto/x509.py where I've tried to make consistent behavoir between python2 and python3.

Problem is that by default user uses str and expects something human readable from it.

Really, you should add sometihng like

if pyver == 2
   __str__ = __bytes__

because __bytes__ method name is not special in Python2.

I think that all ASN1 objects supported by this library should behave similar way. For now most elaborate ASN1 object is X509 certificate.

Now certificate objects have no __str__ method in python3. And I'm not sure that it is good. In python2 __str__ serializes it to der, in python3 __bytes__ does the same. Really I have __bytes__ method in python2 too, but this is just ordinary method there.

@zougloub
Copy link

For what it's worth I have bypassed cms.decrypt() because it's trying to do str() on binary data.

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.

3 participants