diff options
author | Mike Crute <mike@crute.us> | 2017-10-01 01:42:37 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2017-10-01 01:42:37 +0000 |
commit | 37f5aa14e2d43f8b81c6fd6de43be1f67d4c08ee (patch) | |
tree | 485eaa8abefa2fa84db9f93d5f006d04366726af /pandora | |
parent | d25a9f1b797d84be8362dcb36ea70836db10969d (diff) | |
download | pydora-37f5aa14e2d43f8b81c6fd6de43be1f67d4c08ee.tar.bz2 pydora-37f5aa14e2d43f8b81c6fd6de43be1f67d4c08ee.tar.xz pydora-37f5aa14e2d43f8b81c6fd6de43be1f67d4c08ee.zip |
Prefer pure-python crypto if using Python 3
Diffstat (limited to 'pandora')
-rw-r--r-- | pandora/transport.py | 10 |
1 files changed, 9 insertions, 1 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): | |||
313 | return b"".join(self.cipher.encrypt_ecb(self._add_padding(data))) | 313 | return b"".join(self.cipher.encrypt_ecb(self._add_padding(data))) |
314 | 314 | ||
315 | 315 | ||
316 | # Python 3 users can use pure-python mode, if possible prefer that as default | ||
317 | try: | ||
318 | import blowfish | ||
319 | default_crypto_class = PurePythonBlowfish | ||
320 | except ImportError: | ||
321 | default_crypto_class = CryptographyBlowfish | ||
322 | |||
323 | |||
316 | class Encryptor(object): | 324 | class Encryptor(object): |
317 | """Pandora Blowfish Encryptor | 325 | """Pandora Blowfish Encryptor |
318 | 326 | ||
@@ -320,7 +328,7 @@ class Encryptor(object): | |||
320 | API request and response. It handles the formats that the API expects. | 328 | API request and response. It handles the formats that the API expects. |
321 | """ | 329 | """ |
322 | 330 | ||
323 | def __init__(self, in_key, out_key, crypto_class=CryptographyBlowfish): | 331 | def __init__(self, in_key, out_key, crypto_class=default_crypto_class): |
324 | self.bf_out = crypto_class(out_key) | 332 | self.bf_out = crypto_class(out_key) |
325 | self.bf_in = crypto_class(in_key) | 333 | self.bf_in = crypto_class(in_key) |
326 | 334 | ||