about summary refs log tree commit diff
path: root/broadlink/__init__.py
diff options
context:
space:
mode:
authorkost <vlatko.kosturjak@gmail.com>2017-05-07T18·32+0200
committerMatthew Garrett <mjg59-github@srcf.ucam.org>2017-05-07T18·32-0700
commitf7e30344c5748e37924c8a4f28522c2bc99a52ee (patch)
treecb5626e55df38917cf8f0c9d8dce1bad65f1de3b /broadlink/__init__.py
parentf1d62380c96f5fc0c4aa6fb2cd3029fc1690164e (diff)
pad the payload for AES encryption (16) (#92)
Diffstat (limited to 'broadlink/__init__.py')
-rw-r--r--broadlink/__init__.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py
index 3fe28a81c920..e757f90005a8 100644
--- a/broadlink/__init__.py
+++ b/broadlink/__init__.py
@@ -245,6 +245,11 @@ class device:
     packet[0x32] = self.id[2]
     packet[0x33] = self.id[3]
 
+    # pad the payload for AES encryption
+    if len(payload)>0:
+      numpad=(len(payload)//16+1)*16
+      payload=payload.ljust(numpad,"\x00")
+
     checksum = 0xbeaf
     for i in range(len(payload)):
       checksum += payload[i]
@@ -539,4 +544,4 @@ def setup(ssid, password, security_mode):
                        socket.SOCK_DGRAM)  # UDP
   sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
   sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
-  sock.sendto(payload, ('255.255.255.255', 80))
\ No newline at end of file
+  sock.sendto(payload, ('255.255.255.255', 80))