diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-11-07 01:16:33 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-11-07 02:18:30 +0530 |
commit | db4678e448d6e7da9743f4028c94b540fcafc528 (patch) | |
tree | a4878669354f77248567eef6c3cd45318659320d /yt_dlp/aes.py | |
parent | a349d4d6415e9aa0fb11c674e405d57fa13cc7fd (diff) | |
download | hypervideo-pre-db4678e448d6e7da9743f4028c94b540fcafc528.tar.lz hypervideo-pre-db4678e448d6e7da9743f4028c94b540fcafc528.tar.xz hypervideo-pre-db4678e448d6e7da9743f4028c94b540fcafc528.zip |
Update to ytdl-commit-de39d128
[extractor/ceskatelevize] Back-port extractor from yt-dlp
https://github.com/ytdl-org/youtube-dl/commit/de39d1281cea499cb1adfce5ff7e0a56f1bad5fe
Closes #5361, Closes #4634, Closes #5210
Diffstat (limited to 'yt_dlp/aes.py')
-rw-r--r-- | yt_dlp/aes.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/yt_dlp/aes.py b/yt_dlp/aes.py index b428c682b..60ce99cb1 100644 --- a/yt_dlp/aes.py +++ b/yt_dlp/aes.py @@ -28,11 +28,23 @@ def aes_cbc_encrypt_bytes(data, key, iv, **kwargs): return intlist_to_bytes(aes_cbc_encrypt(*map(bytes_to_intlist, (data, key, iv)), **kwargs)) +BLOCK_SIZE_BYTES = 16 + + def unpad_pkcs7(data): return data[:-compat_ord(data[-1])] -BLOCK_SIZE_BYTES = 16 +def pkcs7_padding(data): + """ + PKCS#7 padding + + @param {int[]} data cleartext + @returns {int[]} padding data + """ + + remaining_length = BLOCK_SIZE_BYTES - len(data) % BLOCK_SIZE_BYTES + return data + [remaining_length] * remaining_length def pad_block(block, padding_mode): @@ -64,7 +76,7 @@ def pad_block(block, padding_mode): def aes_ecb_encrypt(data, key, iv=None): """ - Encrypt with aes in ECB mode + Encrypt with aes in ECB mode. Using PKCS#7 padding @param {int[]} data cleartext @param {int[]} key 16/24/32-Byte cipher key @@ -77,8 +89,7 @@ def aes_ecb_encrypt(data, key, iv=None): encrypted_data = [] for i in range(block_count): block = data[i * BLOCK_SIZE_BYTES: (i + 1) * BLOCK_SIZE_BYTES] - encrypted_data += aes_encrypt(block, expanded_key) - encrypted_data = encrypted_data[:len(data)] + encrypted_data += aes_encrypt(pkcs7_padding(block), expanded_key) return encrypted_data @@ -551,5 +562,6 @@ __all__ = [ 'key_expansion', 'pad_block', + 'pkcs7_padding', 'unpad_pkcs7', ] |