Add optional kasa-crypt dependency for speedups (#464)

If installed, use the optimized protocol encryption procedures implemented as a C extension by kasa-crypt (https://pypi.org/project/kasa-crypt/
This commit is contained in:
J. Nick Koston
2023-06-29 19:43:01 -05:00
committed by GitHub
parent 2d42ca301f
commit afd54d11d3
4 changed files with 53 additions and 4 deletions

View File

@@ -219,3 +219,13 @@ class TPLinkSmartHomeProtocol:
return bytes(
TPLinkSmartHomeProtocol._xor_encrypted_payload(ciphertext)
).decode()
# Try to load the kasa_crypt module and if it is available
try:
from kasa_crypt import decrypt, encrypt
TPLinkSmartHomeProtocol.decrypt = decrypt # type: ignore[method-assign]
TPLinkSmartHomeProtocol.encrypt = encrypt # type: ignore[method-assign]
except ImportError:
pass