ctypescrypto icon indicating copy to clipboard operation
ctypescrypto copied to clipboard

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

Open parneshraniga opened this issue 6 years ago • 4 comments

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.

parneshraniga avatar Sep 05 '19 01:09 parneshraniga

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.

vbwagner avatar Sep 05 '19 06:09 vbwagner

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.

parneshraniga avatar Sep 05 '19 06:09 parneshraniga

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.

vbwagner avatar Sep 05 '19 07:09 vbwagner

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

zougloub avatar Jun 26 '21 20:06 zougloub