1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-13 03:00:11 +01:00

Restore Python 3 support (#95)

Use explicit byte literals.

AES encryption padding broken with commit f7e30344c5 under Python 3.
Python 3 support when using pyaes (instead of Crypto.Cipher.AES) now works.
This commit is contained in:
clach04 2018-03-18 15:12:20 -07:00 committed by Matthew Garrett
parent 8d3c9f1e9f
commit 8b593beff9

View File

@ -182,11 +182,11 @@ class device:
def encrypt_pyaes(self, payload):
aes = pyaes.AESModeOfOperationCBC(self.key, iv = bytes(self.iv))
return "".join([aes.encrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)])
return b"".join([aes.encrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)])
def decrypt_pyaes(self, payload):
aes = pyaes.AESModeOfOperationCBC(self.key, iv = bytes(self.iv))
return "".join([aes.decrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)])
return b"".join([aes.decrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)])
def encrypt_pycrypto(self, payload):
aes = AES.new(bytes(self.key), AES.MODE_CBC, bytes(self.iv))
@ -272,7 +272,7 @@ class device:
# pad the payload for AES encryption
if len(payload)>0:
numpad=(len(payload)//16+1)*16
payload=payload.ljust(numpad,b"\x00")
payload=payload.ljust(numpad, b"\x00")
checksum = 0xbeaf
for i in range(len(payload)):