Skip to content

Commit 30d65bc

Browse files
[thread-cert] import Crypto on demand (openthread#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.
1 parent bce7c1a commit 30d65bc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tests/scripts/thread-cert/net_crypto.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
from binascii import hexlify
3535

36-
from Crypto.Cipher import AES
37-
3836

3937
class CryptoEngine:
4038
""" Class responsible for encryption and decryption of data. """
@@ -64,6 +62,8 @@ def encrypt(self, data, message_info):
6462
"""
6563
key, nonce, auth_data = self._crypto_material_creator.create_key_and_nonce_and_authenticated_data(message_info)
6664

65+
from Crypto.Cipher import AES
66+
6767
cipher = AES.new(key, AES.MODE_CCM, nonce, mac_len=self.mic_length)
6868
cipher.update(auth_data)
6969

@@ -83,6 +83,8 @@ def decrypt(self, enc_data, mic, message_info):
8383
"""
8484
key, nonce, auth_data = self._crypto_material_creator.create_key_and_nonce_and_authenticated_data(message_info)
8585

86+
from Crypto.Cipher import AES
87+
8688
cipher = AES.new(key, AES.MODE_CCM, nonce, mac_len=self.mic_length)
8789
cipher.update(auth_data)
8890

0 commit comments

Comments
 (0)