2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from bemani.common import AESCipher
|
|
|
|
|
|
|
|
|
|
|
|
class TestAESCipher(unittest.TestCase):
|
|
|
|
def test_pad(self) -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
aes = AESCipher("a wonderful key")
|
|
|
|
self.assertEqual(aes._pad(""), "0.--------------")
|
|
|
|
self.assertEqual(aes._unpad(aes._pad("")), "")
|
|
|
|
self.assertEqual(aes._pad("1337"), "4.1337----------")
|
|
|
|
self.assertEqual(aes._unpad(aes._pad("1337")), "1337")
|
|
|
|
self.assertEqual(
|
|
|
|
aes._pad("aaaaaaaaaaaaaaaa"), "16.aaaaaaaaaaaaaaaa-------------"
|
|
|
|
)
|
|
|
|
self.assertEqual(aes._unpad(aes._pad("aaaaaaaaaaaaaaaa")), "aaaaaaaaaaaaaaaa")
|
|
|
|
self.assertEqual(aes._pad("aaaaaaaaaaaaa"), "13.aaaaaaaaaaaaa")
|
|
|
|
self.assertEqual(aes._unpad(aes._pad("aaaaaaaaaaaaa")), "aaaaaaaaaaaaa")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def test_crypto(self) -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
aes = AESCipher("a wonderful key")
|
|
|
|
ciphertext = aes.encrypt("testing")
|
2019-12-08 22:43:49 +01:00
|
|
|
plaintext = aes.decrypt(ciphertext)
|
2022-10-15 20:56:30 +02:00
|
|
|
self.assertEqual(plaintext, "testing")
|
2019-12-08 22:43:49 +01:00
|
|
|
self.assertNotEqual(ciphertext, plaintext)
|