[pycrypto] Once again: Python3 with PyCrypto

Dwayne C. Litzenberger dlitz at dlitz.net
Sat Dec 25 10:36:27 CST 2010


I'm on vacation, so I won't be able to look at this until early January, but off the top of my head... does .encode() work in Python 2.1?

"Thorsten Behrens" <sbehrens at gmx.li> wrote:

>Still crashing, just not on importing winrandom any more. I found the 
>typo there. More errors remain, clearly.
>
>I have a question regarding the str/bytes situation in Python 3. Take 
>this example from Counter.py:
>
>     if sys.version_info[0] is 2:
>         if little_endian:
>             return _counter._newLE(str(prefix), str(suffix), initval, 
>allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
>         else:
>             return _counter._newBE(str(prefix), str(suffix), initval, 
>allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
>     else:
>         if little_endian:
>             return _counter._newLE(prefix.encode(), suffix.encode(), 
>initval.encode(), allow_wraparound=allow_wraparound, 
>disable_shortcut=disable_shortcut)
>         else:
>             return _counter._newBE(prefix.encode(), suffix.encode(), 
>initval.encode(), allow_wraparound=allow_wraparound, 
>disable_shortcut=disable_shortcut)
>
>Not having had that much exposure to this code, my question is: Would
>it 
>be safe to just use .encode() throughout, without the check for Python 
>version? From all I can tell, it'll work as desired - but there may be
>a 
>corner case I haven't considered. Essentially, can I collapse the above
>
>again to:
>
>     if little_endian:
>         return _counter._newLE(prefix.encode(), suffix.encode(), 
>initval.encode(), allow_wraparound=allow_wraparound, 
>disable_shortcut=disable_shortcut)
>     else:
>         return _counter._newBE(prefix.encode(), suffix.encode(), 
>initval.encode(), allow_wraparound=allow_wraparound, 
>disable_shortcut=disable_shortcut)
>
>for all versions of Python, 2.x and 3.x.
>
>Dwayne, can you shed some light?
>
>Thorsten
>
>_______________________________________________
>pycrypto mailing list
>pycrypto at lists.dlitz.net
>http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.


More information about the pycrypto mailing list