def test_compressed_encrypt_then_decrypt_string(): plaintext = "X" * 4096 key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key, compress=True) assert_less(len(ciphertext), len(plaintext) / 10) plaintext_after = crypto.decrypt_string(ciphertext, key) assert_equal(plaintext, plaintext_after)
def test_compressed_encrypt_then_decrypt_random_string(): plaintext = os.urandom(1024 * 1024) key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key, compress=True) plaintext_after = crypto.decrypt_string(ciphertext, key) assert_equal(plaintext, plaintext_after)
def test_encrypt_then_decrypt_empty_string(): plaintext = "" key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key) plaintext_after = crypto.decrypt_string(ciphertext, key) assert_equal(plaintext_after, plaintext)
def test_decrypt_with_wrong_password_raises_exception(): plaintext = "this is some text" key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key) another_key = "this is my key 2" plaintext_after = crypto.decrypt_string(ciphertext, another_key)
def test_decrypt_then_damage_raises_exception(): plaintext = "this is some text" key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key) ciphertext = ciphertext[:len(ciphertext)-5] plaintext_after = crypto.decrypt_string(ciphertext, key)
def test_encrypt_then_alter_raises_exception(): plaintext = "this is some text" key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key) ciphertext = ciphertext[:-len(plaintext)] + '\0' * len(plaintext) plaintext_after = crypto.decrypt_string(ciphertext, key)
def test_massive_encrypt_then_decrypt(): plaintext = "X" * 50 * 1024 * 1024 key = "this is my key" ciphertext = crypto.encrypt_string(plaintext, key) plaintext_after = crypto.decrypt_string(ciphertext, key) assert_equal(plaintext, plaintext_after)
def test_ciphertext_not_repeated(): plaintext = "this is some text" key = "this is my key" all_ciphertexts = [crypto.encrypt_string(plaintext, key) for i in xrange(100)] unique_ciphertexts = set(all_ciphertexts) assert_equal(len(unique_ciphertexts), len(all_ciphertexts))