diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-12-28 04:19:20 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-12-28 04:19:20 +0300 |
commit | ae6fc3b6ec1a7c740749e43ca22f61d5a44c9602 (patch) | |
tree | e93d7bf08e21f025485a8ee88839d4e3572691d3 /test/file.py | |
parent | test: refactoring (diff) | |
download | aes-tools-ae6fc3b6ec1a7c740749e43ca22f61d5a44c9602.tar.gz aes-tools-ae6fc3b6ec1a7c740749e43ca22f61d5a44c9602.zip |
test: refactoring
Diffstat (limited to 'test/file.py')
-rw-r--r-- | test/file.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/test/file.py b/test/file.py index d1abc3d..03a12de 100644 --- a/test/file.py +++ b/test/file.py @@ -21,13 +21,13 @@ _IV_EXT = 'iv' _PLAIN_EXT = 'plain' _CIPHER_EXT = 'cipher' -def _run_encryption_test(tools, tmp_dir, algo, mode, key, plain_path, cipher_path, iv=None, force=False): +def _run_encryption_test(tools, tmp_dir, algorithm, mode, key, plain_path, cipher_path, iv=None, force=False): logging.info('Running encryption test...') logging.info('\tPlaintext file path: ' + plain_path) logging.info('\tExpected ciphertext file path: ' + cipher_path) tmp_path = os.path.join(tmp_dir, os.path.basename(cipher_path)) logging.info('\tEncrypted file path: ' + tmp_path) - tools.run_encrypt_file(algo, mode, key, plain_path, tmp_path, iv) + tools.run_encrypt_file(algorithm, mode, key, plain_path, tmp_path, iv) if force: logging.warn('Overwriting expected ciphertext file') shutil.copy(tmp_path, cipher_path) @@ -38,13 +38,13 @@ def _run_encryption_test(tools, tmp_dir, algo, mode, key, plain_path, cipher_pat logging.error('The encrypted file doesn\'t match the ciphertext file') return _TestExitCode.FAILURE -def _run_decryption_test(tools, tmp_dir, algo, mode, key, cipher_path, plain_path, iv=None): +def _run_decryption_test(tools, tmp_dir, algorithm, mode, key, cipher_path, plain_path, iv=None): logging.info('Running decryption test...') logging.info('\tCiphertext file path: ' + cipher_path) logging.info('\tExpected plaintext file path: ' + plain_path) tmp_path = os.path.join(tmp_dir, os.path.basename(cipher_path)) logging.info('\tDecrypted file path: ' + tmp_path) - tools.run_decrypt_file(algo, mode, key, cipher_path, tmp_path, iv) + tools.run_decrypt_file(algorithm, mode, key, cipher_path, tmp_path, iv) if filecmp.cmp(tmp_path, plain_path): return _TestExitCode.SUCCESS else: @@ -92,16 +92,16 @@ def _run_tests(tools, suite_dir, force=False): suite_dir = os.path.abspath(suite_dir) logging.info('Suite directory path: ' + suite_dir) with TemporaryDirectory() as tmp_dir: - for algo_dir in _list_dirs(suite_dir): - algo = os.path.basename(algo_dir) - maybe_algo = toolkit.is_algorithm_supported(algo) - if maybe_algo is None: - logging.warn('Unknown or unsupported algorithm: ' + algo) + for algorithm_dir in _list_dirs(suite_dir): + algorithm = os.path.basename(algorithm_dir) + maybe_algorithm = toolkit.is_algorithm_supported(algorithm) + if maybe_algorithm is None: + logging.warn('Unknown or unsupported algorithm: ' + algorithm) exit_codes.append(_TestExitCode.SKIPPED) continue - algo = maybe_algo - logging.info('Algorithm: ' + algo) - for mode_dir in _list_dirs(algo_dir): + algorithm = maybe_algorithm + logging.info('Algorithm: ' + algorithm) + for mode_dir in _list_dirs(algorithm_dir): mode = os.path.basename(mode_dir) maybe_mode = toolkit.is_mode_supported(mode) if maybe_mode is None: @@ -121,11 +121,11 @@ def _run_tests(tools, suite_dir, force=False): iv = _read_iv(iv_path) plain_path = _build_plain_path(key_path) cipher_path = _build_cipher_path(key_path) - os.makedirs(os.path.join(tmp_dir, algo, mode), 0o777, True) + os.makedirs(os.path.join(tmp_dir, algorithm, mode), 0o777, True) try: exit_codes.append(_run_encryption_test( - tools, os.path.join(tmp_dir, algo, mode), - algo, mode, key, plain_path, cipher_path, iv, force)) + tools, os.path.join(tmp_dir, algorithm, mode), + algorithm, mode, key, plain_path, cipher_path, iv, force)) except Exception as e: logging.error('Encountered an exception!') logging.exception(e) @@ -133,8 +133,8 @@ def _run_tests(tools, suite_dir, force=False): if not force: try: exit_codes.append(_run_decryption_test( - tools, os.path.join(tmp_dir, algo, mode), - algo, mode, key, cipher_path, plain_path, iv)) + tools, os.path.join(tmp_dir, algorithm, mode), + algorithm, mode, key, cipher_path, plain_path, iv)) except Exception as e: logging.error('Encountered an exception!') logging.exception(e) |