[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.
This commit is contained in:
Simon Lin
2022-08-31 19:48:24 -07:00
committed by GitHub
parent bce7c1ae1f
commit 30d65bca48
+4 -2
View File
@@ -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)