aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/aes.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-09-18 00:51:27 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-09-18 00:55:58 +0530
commitedf65256aa630a5ce011138e8957c95c9bef0584 (patch)
treefa1f3c3b18db2afb6f47081355c4fd23f4ae975b /yt_dlp/aes.py
parent7303f84abeeb283b15806f7ef47bfe694f55b99c (diff)
downloadhypervideo-pre-edf65256aa630a5ce011138e8957c95c9bef0584.tar.lz
hypervideo-pre-edf65256aa630a5ce011138e8957c95c9bef0584.tar.xz
hypervideo-pre-edf65256aa630a5ce011138e8957c95c9bef0584.zip
[hls,aes] Fallback to native implementation for AES-CBC
and detect `Cryptodome` in addition to `Crypto` Closes #935 Related: #938
Diffstat (limited to 'yt_dlp/aes.py')
-rw-r--r--yt_dlp/aes.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/yt_dlp/aes.py b/yt_dlp/aes.py
index 461bb6d41..57caae069 100644
--- a/yt_dlp/aes.py
+++ b/yt_dlp/aes.py
@@ -2,9 +2,21 @@ from __future__ import unicode_literals
from math import ceil
-from .compat import compat_b64decode
+from .compat import compat_b64decode, compat_pycrypto_AES
from .utils import bytes_to_intlist, intlist_to_bytes
+
+if compat_pycrypto_AES:
+ def aes_cbc_decrypt_bytes(data, key, iv):
+ """ Decrypt bytes with AES-CBC using pycryptodome """
+ return compat_pycrypto_AES.new(key, compat_pycrypto_AES.MODE_CBC, iv).decrypt(data)
+
+else:
+ def aes_cbc_decrypt_bytes(data, key, iv):
+ """ Decrypt bytes with AES-CBC using native implementation since pycryptodome is unavailable """
+ return intlist_to_bytes(aes_cbc_decrypt(*map(bytes_to_intlist, (data, key, iv))))
+
+
BLOCK_SIZE_BYTES = 16