aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2017-02-27 18:50:19 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2017-02-28 22:10:31 +0800
commitf48409c7ac186fa38bbeb2df2b210e37a18eb04b (patch)
tree8046e12170bfafc7b0e62bd37e968833d1ce1156 /youtube_dl
parentc9619f0a17927086c49e4b443202be296d734a76 (diff)
[utils] Add pkcs1pad
Used in daisuki.net (#4738)
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 17b83794a..8bd075eaf 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -3336,6 +3336,21 @@ def ohdave_rsa_encrypt(data, exponent, modulus):
return '%x' % encrypted
+def pkcs1pad(data, length):
+ """
+ Padding input data with PKCS#1 scheme
+
+ @param {int[]} data input data
+ @param {int} length target length
+ @returns {int[]} padded data
+ """
+ if len(data) > length - 11:
+ raise ValueError('Input data too long for PKCS#1 padding')
+
+ pseudo_random = [random.randint(0, 254) for _ in range(length - len(data) - 3)]
+ return [0, 2] + pseudo_random + [0] + data
+
+
def encode_base_n(num, n, table=None):
FULL_TABLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
if not table: