ctypescrypto
ctypescrypto copied to clipboard
Added option to return Enveloped data as bytes as well as strings.
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.
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.
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.
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.
For what it's worth I have bypassed cms.decrypt() because it's trying to do str() on binary data.