From 30d65bca4896a38e0e8a9e0b3cb0b9d458454ef2 Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Thu, 1 Sep 2022 10:48:24 +0800 Subject: [PATCH] [thread-cert] import `Crypto` on demand (#8109) This commit imports `Crypto` module only when it's used. This helps thread-cert tests that do not use message factory to run without having to install `Crypto` module. --- tests/scripts/thread-cert/net_crypto.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/scripts/thread-cert/net_crypto.py b/tests/scripts/thread-cert/net_crypto.py index 66533b9f7..d9d007f1c 100755 --- a/tests/scripts/thread-cert/net_crypto.py +++ b/tests/scripts/thread-cert/net_crypto.py @@ -33,8 +33,6 @@ import struct from binascii import hexlify -from Crypto.Cipher import AES - class CryptoEngine: """ Class responsible for encryption and decryption of data. """ @@ -64,6 +62,8 @@ class CryptoEngine: """ key, nonce, auth_data = self._crypto_material_creator.create_key_and_nonce_and_authenticated_data(message_info) + from Crypto.Cipher import AES + cipher = AES.new(key, AES.MODE_CCM, nonce, mac_len=self.mic_length) cipher.update(auth_data) @@ -83,6 +83,8 @@ class CryptoEngine: """ key, nonce, auth_data = self._crypto_material_creator.create_key_and_nonce_and_authenticated_data(message_info) + from Crypto.Cipher import AES + cipher = AES.new(key, AES.MODE_CCM, nonce, mac_len=self.mic_length) cipher.update(auth_data)