comparison src/test/test_memory_crypto.py @ 1066:cbf917a90784

test (memory): fixes crypto encryption/decryption test
author souliane <souliane@mailoo.org>
date Thu, 12 Jun 2014 15:57:22 +0200
parents 127c96020022
children 77cd312d32c4
comparison
equal deleted inserted replaced
1065:9378c80e3408 1066:cbf917a90784
32 def setUp(self): 32 def setUp(self):
33 self.host = helpers.FakeSAT() 33 self.host = helpers.FakeSAT()
34 34
35 def test_encrypt_decrypt(self): 35 def test_encrypt_decrypt(self):
36 d_list = [] 36 d_list = []
37
38 def test(key, message):
39 d = BlockCipher.encrypt(key, message)
40 d.addCallback(lambda ciphertext: BlockCipher.decrypt(key, ciphertext))
41 d.addCallback(lambda decrypted: self.assertEqual(message, decrypted))
42 d_list.append(d)
43
37 for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40): 44 for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40):
38 key = urandom(key_len) 45 key = urandom(key_len)
39 for message_len in (0, 2, 16, 24, 32, 100): 46 for message_len in (0, 2, 16, 24, 32, 100):
40 message = urandom(message_len) 47 message = urandom(message_len)
41 d = BlockCipher.encrypt(key, message) 48 test(key, message)
42 d.addCallback(lambda ciphertext: lambda key, cipher: BlockCipher.decrypt(key, ciphertext))
43 d.addCallback(lambda decrypted: lambda message, decrypted: self.assertEqual(message, decrypted))
44 d_list.append(d)
45 return defer.DeferredList(d_list) 49 return defer.DeferredList(d_list)
46 50
47 def test_hash_verify(self): 51 def test_hash_verify(self):
48 d_list = [] 52 d_list = []
49 for password in (0, 2, 8, 10, 16, 24, 30, 32, 40): 53 for password in (0, 2, 8, 10, 16, 24, 30, 32, 40):