mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-22 07:00:12 +01:00
Remove support for pyaes (#281)
* remove support for pyaes * remove support for pyaes * remove support for pyaes
This commit is contained in:
parent
11c5981793
commit
2e5361bd8e
@ -7,11 +7,8 @@ import threading
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
try:
|
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
except ImportError:
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
import pyaes
|
|
||||||
|
|
||||||
|
|
||||||
def gendevice(devtype, host, mac):
|
def gendevice(devtype, host, mac):
|
||||||
@ -159,39 +156,20 @@ class device:
|
|||||||
self.type = "Unknown"
|
self.type = "Unknown"
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
if 'pyaes' in globals():
|
|
||||||
self.encrypt = self.encrypt_pyaes
|
|
||||||
self.decrypt = self.decrypt_pyaes
|
|
||||||
self.update_aes = self.update_aes_pyaes
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.encrypt = self.encrypt_crypto
|
|
||||||
self.decrypt = self.decrypt_crypto
|
|
||||||
self.update_aes = self.update_aes_crypto
|
|
||||||
|
|
||||||
self.aes = None
|
self.aes = None
|
||||||
key = bytearray(
|
key = bytearray(
|
||||||
[0x09, 0x76, 0x28, 0x34, 0x3f, 0xe9, 0x9e, 0x23, 0x76, 0x5c, 0x15, 0x13, 0xac, 0xcf, 0x8b, 0x02])
|
[0x09, 0x76, 0x28, 0x34, 0x3f, 0xe9, 0x9e, 0x23, 0x76, 0x5c, 0x15, 0x13, 0xac, 0xcf, 0x8b, 0x02])
|
||||||
self.update_aes(key)
|
self.update_aes(key)
|
||||||
|
|
||||||
def update_aes_pyaes(self, key):
|
def update_aes(self, key):
|
||||||
self.aes = pyaes.AESModeOfOperationCBC(key, iv=bytes(self.iv))
|
|
||||||
|
|
||||||
def encrypt_pyaes(self, payload):
|
|
||||||
return b"".join([self.aes.encrypt(bytes(payload[i:i + 16])) for i in range(0, len(payload), 16)])
|
|
||||||
|
|
||||||
def decrypt_pyaes(self, payload):
|
|
||||||
return b"".join([self.aes.decrypt(bytes(payload[i:i + 16])) for i in range(0, len(payload), 16)])
|
|
||||||
|
|
||||||
def update_aes_crypto(self, key):
|
|
||||||
self.aes = Cipher(algorithms.AES(key), modes.CBC(self.iv),
|
self.aes = Cipher(algorithms.AES(key), modes.CBC(self.iv),
|
||||||
backend=default_backend())
|
backend=default_backend())
|
||||||
|
|
||||||
def encrypt_crypto(self, payload):
|
def encrypt(self, payload):
|
||||||
encryptor = self.aes.encryptor()
|
encryptor = self.aes.encryptor()
|
||||||
return encryptor.update(payload) + encryptor.finalize()
|
return encryptor.update(payload) + encryptor.finalize()
|
||||||
|
|
||||||
def decrypt_crypto(self, payload):
|
def decrypt(self, payload):
|
||||||
decryptor = self.aes.decryptor()
|
decryptor = self.aes.decryptor()
|
||||||
return decryptor.update(payload) + decryptor.finalize()
|
return decryptor.update(payload) + decryptor.finalize()
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import broadlink
|
|
||||||
import sys
|
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
|
||||||
import base64
|
import base64
|
||||||
import codecs
|
import codecs
|
||||||
|
import time
|
||||||
|
|
||||||
|
import broadlink
|
||||||
|
|
||||||
TICK = 32.84
|
TICK = 32.84
|
||||||
IR_TOKEN = 0x26
|
IR_TOKEN = 0x26
|
||||||
@ -18,7 +18,6 @@ def auto_int(x):
|
|||||||
def to_microseconds(bytes):
|
def to_microseconds(bytes):
|
||||||
result = []
|
result = []
|
||||||
# print bytes[0] # 0x26 = 38for IR
|
# print bytes[0] # 0x26 = 38for IR
|
||||||
length = bytes[2] + 256 * bytes[3] # presently ignored
|
|
||||||
index = 4
|
index = 4
|
||||||
while index < len(bytes):
|
while index < len(bytes):
|
||||||
chunk = bytes[index]
|
chunk = bytes[index]
|
||||||
@ -83,7 +82,8 @@ parser.add_argument("--sensors", action="store_true", help="check all sensors")
|
|||||||
parser.add_argument("--learn", action="store_true", help="learn command")
|
parser.add_argument("--learn", action="store_true", help="learn command")
|
||||||
parser.add_argument("--rfscanlearn", action="store_true", help="rf scan learning")
|
parser.add_argument("--rfscanlearn", action="store_true", help="rf scan learning")
|
||||||
parser.add_argument("--learnfile", help="save learned command to a specified file")
|
parser.add_argument("--learnfile", help="save learned command to a specified file")
|
||||||
parser.add_argument("--durations", action="store_true", help="use durations in micro seconds instead of the Broadlink format")
|
parser.add_argument("--durations", action="store_true",
|
||||||
|
help="use durations in micro seconds instead of the Broadlink format")
|
||||||
parser.add_argument("--convert", action="store_true", help="convert input data to durations")
|
parser.add_argument("--convert", action="store_true", help="convert input data to durations")
|
||||||
parser.add_argument("data", nargs='*', help="Data to send or convert")
|
parser.add_argument("data", nargs='*', help="Data to send or convert")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import broadlink
|
|
||||||
import time
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(fromfile_prefix_chars='@');
|
import broadlink
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
||||||
parser.add_argument("--timeout", type=int, default=5, help="timeout to wait for receiving discovery responses")
|
parser.add_argument("--timeout", type=int, default=5, help="timeout to wait for receiving discovery responses")
|
||||||
parser.add_argument("--ip", default=None, help="ip address to use in the discovery")
|
parser.add_argument("--ip", default=None, help="ip address to use in the discovery")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -15,7 +15,8 @@ for device in devices:
|
|||||||
if device.auth():
|
if device.auth():
|
||||||
print("###########################################")
|
print("###########################################")
|
||||||
print(device.type)
|
print(device.type)
|
||||||
print("# broadlink_cli --type {} --host {} --mac {}".format(hex(device.devtype), device.host[0], ''.join(format(x, '02x') for x in device.mac)))
|
print("# broadlink_cli --type {} --host {} --mac {}".format(hex(device.devtype), device.host[0],
|
||||||
|
''.join(format(x, '02x') for x in device.mac)))
|
||||||
print("Device file data (to be used with --device @filename in broadlink_cli) : ")
|
print("Device file data (to be used with --device @filename in broadlink_cli) : ")
|
||||||
print("{} {} {}".format(hex(device.devtype), device.host[0], ''.join(format(x, '02x') for x in device.mac)))
|
print("{} {} {}".format(hex(device.devtype), device.host[0], ''.join(format(x, '02x') for x in device.mac)))
|
||||||
if hasattr(device, 'check_temperature'):
|
if hasattr(device, 'check_temperature'):
|
||||||
@ -23,4 +24,3 @@ for device in devices:
|
|||||||
print("")
|
print("")
|
||||||
else:
|
else:
|
||||||
print("Error authenticating with device : {}".format(device.host))
|
print("Error authenticating with device : {}".format(device.host))
|
||||||
|
|
||||||
|
13
setup.py
13
setup.py
@ -1,20 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
try:
|
|
||||||
import cryptography
|
|
||||||
dynamic_requires = ['cryptography>=2.1.1']
|
|
||||||
except ImportError:
|
|
||||||
dynamic_requires = ["pyaes==1.6.0"]
|
|
||||||
|
|
||||||
# For Hysen thermostatic heating controller
|
|
||||||
dynamic_requires.append('PyCRC')
|
|
||||||
|
|
||||||
version = '0.11.1'
|
version = '0.11.1'
|
||||||
|
|
||||||
@ -26,7 +15,7 @@ setup(
|
|||||||
url='http://github.com/mjg59/python-broadlink',
|
url='http://github.com/mjg59/python-broadlink',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
scripts=[],
|
scripts=[],
|
||||||
install_requires=dynamic_requires,
|
install_requires=['cryptography>=2.1.1', 'PyCRC'],
|
||||||
description='Python API for controlling Broadlink IR controllers',
|
description='Python API for controlling Broadlink IR controllers',
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 4 - Beta',
|
'Development Status :: 4 - Beta',
|
||||||
|
Loading…
Reference in New Issue
Block a user