From 37f5aa14e2d43f8b81c6fd6de43be1f67d4c08ee Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Sun, 1 Oct 2017 01:42:37 +0000 Subject: Prefer pure-python crypto if using Python 3 --- pandora/transport.py | 10 +++++++++- setup.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pandora/transport.py b/pandora/transport.py index aeba50d..f609cee 100644 --- a/pandora/transport.py +++ b/pandora/transport.py @@ -313,6 +313,14 @@ class PurePythonBlowfish(BlowfishCryptor): return b"".join(self.cipher.encrypt_ecb(self._add_padding(data))) +# Python 3 users can use pure-python mode, if possible prefer that as default +try: + import blowfish + default_crypto_class = PurePythonBlowfish +except ImportError: + default_crypto_class = CryptographyBlowfish + + class Encryptor(object): """Pandora Blowfish Encryptor @@ -320,7 +328,7 @@ class Encryptor(object): API request and response. It handles the formats that the API expects. """ - def __init__(self, in_key, out_key, crypto_class=CryptographyBlowfish): + def __init__(self, in_key, out_key, crypto_class=default_crypto_class): self.bf_out = crypto_class(out_key) self.bf_in = crypto_class(in_key) diff --git a/setup.py b/setup.py index f747ad0..431775d 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,8 @@ setup( "coverage>=4.1,<5", ], install_requires=[ - "cryptography>=2,<3", + 'cryptography>=2,<3;python_version<"3.4"', + 'blowfish<1.0;python_version>="3.4"', "requests>=2,<3", ], entry_points={ -- cgit v1.2.3