unittest for aes_ecb_encrypt
This commit is contained in:
parent
f963bfba79
commit
d00e73c8ea
@ -8,9 +8,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from youtube_dl.aes import aes_decrypt, aes_encrypt, aes_cbc_decrypt, aes_cbc_encrypt, aes_decrypt_text
|
from youtube_dl.aes import aes_decrypt, aes_encrypt, aes_cbc_decrypt, aes_cbc_encrypt, aes_decrypt_text, aes_ecb_encrypt
|
||||||
from youtube_dl.utils import bytes_to_intlist, intlist_to_bytes
|
from youtube_dl.utils import bytes_to_intlist, intlist_to_bytes
|
||||||
import base64
|
import base64
|
||||||
|
from binascii import a2b_hex
|
||||||
|
|
||||||
# the encrypted data can be generate with 'devscripts/generate_aes_testdata.py'
|
# the encrypted data can be generate with 'devscripts/generate_aes_testdata.py'
|
||||||
|
|
||||||
@ -41,6 +42,16 @@ class TestAES(unittest.TestCase):
|
|||||||
encrypted,
|
encrypted,
|
||||||
b"\x97\x92+\xe5\x0b\xc3\x18\x91ky9m&\xb3\xb5@\xe6'\xc2\x96.\xc8u\x88\xab9-[\x9e|\xf1\xcd")
|
b"\x97\x92+\xe5\x0b\xc3\x18\x91ky9m&\xb3\xb5@\xe6'\xc2\x96.\xc8u\x88\xab9-[\x9e|\xf1\xcd")
|
||||||
|
|
||||||
|
def test_ecb_encrypt(self):
|
||||||
|
key = a2b_hex("0123456789abcdeff0e1d2c3b4a59687")
|
||||||
|
data = a2b_hex("6b77b4d63006dee605b156e27403979358deb9e7154616d90123456789abcdef")
|
||||||
|
check = a2b_hex("1498ad525d546566da51197e5cd8c5487360057efbf565f10de06b58626aef28")
|
||||||
|
|
||||||
|
data = bytes_to_intlist(data)
|
||||||
|
key = bytes_to_intlist(key)
|
||||||
|
encrypted = intlist_to_bytes(aes_ecb_encrypt(data, key))
|
||||||
|
self.assertEqual(encrypted, check)
|
||||||
|
|
||||||
def test_decrypt_text(self):
|
def test_decrypt_text(self):
|
||||||
password = intlist_to_bytes(self.key).decode('utf-8')
|
password = intlist_to_bytes(self.key).decode('utf-8')
|
||||||
encrypted = base64.b64encode(
|
encrypted = base64.b64encode(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user