]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Replace str.decode('hex') with binascii.unhexlify() for python3
authorMasashi Honma <masashi.honma@gmail.com>
Sat, 2 Feb 2019 16:01:41 +0000 (18:01 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 4 Feb 2019 10:26:34 +0000 (12:26 +0200)
Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/test_dbus.py
tests/hwsim/test_macsec.py
tests/hwsim/test_mbo.py
tests/hwsim/test_sigma_dut.py

index 2e6b9336c50964fc95ebd04577889a4a526a3ea0..338c1dd90dfc2b9118484898e7e69484535a8cc0 100644 (file)
@@ -776,7 +776,7 @@ def _test_dbus_wps_pin(dev, apdev):
 
         def start_pin(self, *args):
             logger.debug("start_pin")
-            bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
+            bssid_ay = dbus.ByteArray(binascii.unhexlify(bssid.replace(':','').encode()))
             wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670',
                        'Bssid': bssid_ay})
             return False
@@ -836,7 +836,7 @@ def _test_dbus_wps_pin2(dev, apdev):
 
         def start_pin(self, *args):
             logger.debug("start_pin")
-            bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
+            bssid_ay = dbus.ByteArray(binascii.unhexlify(bssid.replace(':','').encode()))
             res = wps.Start({'Role': 'enrollee', 'Type': 'pin',
                              'Bssid': bssid_ay})
             pin = res['Pin']
@@ -902,7 +902,7 @@ def _test_dbus_wps_pin_m2d(dev, apdev):
 
         def start_pin(self, *args):
             logger.debug("start_pin")
-            bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
+            bssid_ay = dbus.ByteArray(binascii.unhexlify(bssid.replace(':','').encode()))
             wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670',
                        'Bssid': bssid_ay})
             return False
@@ -957,7 +957,7 @@ def _test_dbus_wps_reg(dev, apdev):
 
         def start_reg(self, *args):
             logger.debug("start_reg")
-            bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
+            bssid_ay = dbus.ByteArray(binascii.unhexlify(bssid.replace(':','').encode()))
             wps.Start({'Role': 'registrar', 'Type': 'pin',
                        'Pin': '12345670', 'Bssid': bssid_ay})
             return False
@@ -981,7 +981,7 @@ def test_dbus_wps_cancel(dev, apdev):
 
     wps.Cancel()
     dev[0].scan_for_bss(bssid, freq="2412")
-    bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
+    bssid_ay = dbus.ByteArray(binascii.unhexlify(bssid.replace(':','').encode()))
     wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670',
                'Bssid': bssid_ay})
     wps.Cancel()
index cc9bd3973ec4402cf8a5e51477c726408d83be89..e760e76be8e645041ac826f0012da4e9b7d8eb20 100644 (file)
@@ -6,6 +6,7 @@
 
 import logging
 logger = logging.getLogger()
+import binascii
 import os
 import signal
 import subprocess
@@ -175,9 +176,9 @@ def lower_addr(addr1, addr2):
     a1 = addr1.split(':')
     a2 = addr2.split(':')
     for i in range(6):
-        if a1[i].decode("hex") < a2[i].decode("hex"):
+        if binascii.unhexlify(a1[i]) < binascii.unhexlify(a2[i]):
             return True
-        if a1[i].decode("hex") > a2[i].decode("hex"):
+        if binascii.unhexlify(a1[i]) > binascii.unhexlify(a2[i]):
             return False
     return False
 
index a36aee2ba6cf919276762585a29b8482a1fd3a9e..2a177c6098ee1c8a874c9fc25ef2ea43dcfe749f 100644 (file)
@@ -449,7 +449,7 @@ def test_mbo_sta_supp_op_classes(dev, apdev):
     logger.debug("STA: " + str(sta))
     if 'supp_op_classes' not in sta:
         raise Exception("No supp_op_classes")
-    supp = bytearray(sta['supp_op_classes'].decode("hex"))
+    supp = bytearray(binascii.unhexlify(sta['supp_op_classes']))
     if supp[0] != 81:
         raise Exception("Unexpected current operating class %d" % supp[0])
     if 115 not in supp:
index 8bc45d967fc31c1338e0f89f9ab23c6298310415..9375421bfbd4f4106ca26f903f3fd9350de6fc01 100644 (file)
@@ -30,6 +30,9 @@ def check_sigma_dut():
 def to_hex(s):
     return binascii.hexlify(s.encode()).decode()
 
+def from_hex(s):
+    return binascii.unhexlify(s).decode()
+
 def sigma_dut_cmd(cmd, port=9000, timeout=2):
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                          socket.IPPROTO_TCP)
@@ -968,7 +971,7 @@ def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
-        uri = hex.decode('hex')
+        uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
 
         res = dev[1].request("DPP_QR_CODE " + uri)
@@ -1105,7 +1108,7 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra=''):
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
-        uri = hex.decode('hex')
+        uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
 
         res = dev[1].request("DPP_QR_CODE " + uri)
@@ -1189,7 +1192,7 @@ def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
-        uri = hex.decode('hex')
+        uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
 
         res = dev[1].request("DPP_QR_CODE " + uri)
@@ -1288,7 +1291,7 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
-        uri = hex.decode('hex')
+        uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
 
         if not resp_pending:
@@ -1485,7 +1488,7 @@ def test_sigma_dut_dpp_incompatible_roles_init(dev, apdev):
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
-        uri = hex.decode('hex')
+        uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
 
         res = dev[1].request("DPP_QR_CODE " + uri)
@@ -1539,7 +1542,7 @@ def test_sigma_dut_dpp_incompatible_roles_resp(dev, apdev):
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
-        uri = hex.decode('hex')
+        uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
 
         res = dev[1].request("DPP_QR_CODE " + uri)
@@ -1629,7 +1632,7 @@ def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""):
             if "status,COMPLETE" not in res:
                 raise Exception("dev_exec_action did not succeed: " + res)
             hex = res.split(',')[3]
-            uri = hex.decode('hex')
+            uri = from_hex(hex)
             logger.info("URI from sigma_dut: " + uri)
 
             cmd = "DPP_CONFIGURATOR_ADD"
@@ -1850,7 +1853,7 @@ def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
     if "status,COMPLETE" not in res:
         raise Exception("dev_exec_action did not succeed: " + res)
     hex = res.split(',')[3]
-    uri = hex.decode('hex')
+    uri = from_hex(hex)
     logger.info("URI from sigma_dut: " + uri)
 
     res = dev[1].request("DPP_QR_CODE " + uri)
@@ -1992,7 +1995,7 @@ def run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail):
     if "status,COMPLETE" not in res:
         raise Exception("dev_exec_action did not succeed: " + res)
     hex = res.split(',')[3]
-    uri = hex.decode('hex')
+    uri = from_hex(hex)
     logger.info("URI from sigma_dut: " + uri)
 
     res = dev[1].request("DPP_QR_CODE " + uri)