From 7d94c8001901a0c8f16d835fa8bb32e6b8ac74d5 Mon Sep 17 00:00:00 2001 From: uzlonewolf Date: Wed, 15 Nov 2023 18:49:09 -0800 Subject: [PATCH] Require pyca/cryptography>=3.1 --- requirements.txt | 2 +- tinytuya/core.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 25f395c9..aec15615 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # -cryptography # Encryption - AES can also be provided via PyCryptodome or pyaes or pyca/cryptography +cryptography>=3.1 # Encryption - AES can also be provided via PyCryptodome or pyaes or pyca/cryptography requests # Used for Setup Wizard - Tuya IoT Platform calls colorama # Makes ANSI escape character sequences work under MS Windows. diff --git a/tinytuya/core.py b/tinytuya/core.py index 6637152f..509437e0 100644 --- a/tinytuya/core.py +++ b/tinytuya/core.py @@ -92,10 +92,13 @@ Crypto = AES = CRYPTOLIB = None try: if clib == 'pyca/cryptography': # https://cryptography.io/en/latest/ + from cryptography import __version__ as Crypto_version + if (Crypto_version[:2] == '0.') or (Crypto_version[:2] == '1.') or (Crypto_version[:2] == '2.') or (Crypto_version == '3.0'): + # cryptography <= 3.0 requires a backend= parameter + continue from cryptography.hazmat.primitives.ciphers import Cipher as Crypto from cryptography.hazmat.primitives.ciphers import modes as Crypto_modes from cryptography.hazmat.primitives.ciphers.algorithms import AES - from cryptography import __version__ as Crypto_version elif clib == 'PyCryptodomex': # https://pycryptodome.readthedocs.io/en/latest/ # PyCryptodome is installed as "Cryptodome" when installed by # `apt install python3-pycryptodome` or `pip install pycryptodomex`