diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-01-30 05:08:09 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-01-30 05:08:09 +0300 |
commit | f1db7d4b218e6edbad2422b170af256d5247cb4e (patch) | |
tree | c1876bd10ed3530ba2505640d5c1437d9ce5e38d /test | |
parent | nist-sp-800-38a.py -> nist.py (diff) | |
download | aes-tools-f1db7d4b218e6edbad2422b170af256d5247cb4e.tar.gz aes-tools-f1db7d4b218e6edbad2422b170af256d5247cb4e.zip |
test: code style
Diffstat (limited to 'test')
-rw-r--r-- | test/cavp.py | 3 | ||||
-rw-r--r-- | test/nist.py | 12 | ||||
-rw-r--r-- | test/toolkit.py | 30 |
3 files changed, 28 insertions, 17 deletions
diff --git a/test/cavp.py b/test/cavp.py index 87c582f..e52f19f 100644 --- a/test/cavp.py +++ b/test/cavp.py @@ -235,8 +235,7 @@ def _parse_args(args=None): return parser.parse_args(args) def main(args=None): - args = _parse_args(args) - return run_tests(**vars(args)) + return run_tests(**vars(_parse_args(args))) if __name__ == '__main__': sys.exit(main()) diff --git a/test/nist.py b/test/nist.py index 3aa9ed2..d0fd6ce 100644 --- a/test/nist.py +++ b/test/nist.py @@ -184,7 +184,8 @@ def run_encryption_test(tools, algorithm, mode, use_boxes=False): iv = get_test_iv(algorithm, mode) expected_ciphertexts = get_test_ciphertexts(algorithm, mode) input_ = BlockInput(key, plaintexts, iv=iv) - actual_ciphertexts = tools.run_encrypt_block(algorithm, mode, input_, use_boxes) + actual_ciphertexts = tools.run_encrypt_block( + algorithm, mode, input_, use_boxes) if verify_test_output(actual_ciphertexts, expected_ciphertexts): return TestExitCode.SUCCESS else: @@ -205,7 +206,8 @@ def run_decryption_test(tools, algorithm, mode, use_boxes=False): iv = get_test_iv(algorithm, mode) expected_plaintexts = get_test_plaintexts(algorithm, mode) input_ = BlockInput(key, ciphertexts, iv=iv) - actual_plaintexts = tools.run_decrypt_block(algorithm, mode, input_, use_boxes) + actual_plaintexts = tools.run_decrypt_block( + algorithm, mode, input_, use_boxes) if verify_test_output(actual_plaintexts, expected_plaintexts): return TestExitCode.SUCCESS else: @@ -232,8 +234,10 @@ def run_tests(tools_path=(), use_sde=False, use_boxes=False, log_path=None): exit_codes = [] for algorithm, mode in get_tested_algorithms_and_modes(): - exit_codes.append(run_encryption_test(tools, algorithm, mode, use_boxes=use_boxes)) - exit_codes.append(run_decryption_test(tools, algorithm, mode, use_boxes=use_boxes)) + exit_codes.append(run_encryption_test( + tools, algorithm, mode, use_boxes=use_boxes)) + exit_codes.append(run_decryption_test( + tools, algorithm, mode, use_boxes=use_boxes)) logging.info('Test exit codes:') logging.info('\tSkipped: %d', exit_codes.count(TestExitCode.SKIPPED)) diff --git a/test/toolkit.py b/test/toolkit.py index b4d0d08..bc27dc8 100644 --- a/test/toolkit.py +++ b/test/toolkit.py @@ -123,15 +123,17 @@ class Tools: return args def run_encrypt_block(self, algorithm, mode, inputs, use_boxes=False): - return self.run(self._ENCRYPT_BLOCK, - self._build_block_args(algorithm, mode, inputs, use_boxes)) + args = self._build_block_args(algorithm, mode, inputs, use_boxes) + return self.run(self._ENCRYPT_BLOCK, args) def run_decrypt_block(self, algorithm, mode, inputs, use_boxes=False): - return self.run(self._DECRYPT_BLOCK, - self._build_block_args(algorithm, mode, inputs, use_boxes)) + args = self._build_block_args(algorithm, mode, inputs, use_boxes) + return self.run(self._DECRYPT_BLOCK, args) @staticmethod - def _file_settings_to_args(algorithm, mode, key, input_path, output_path, iv=None): + def _build_file_args( + algorithm, mode, key, input_path, output_path, iv=None): + args = [ '--algorithm', str(algorithm), '--mode', str(mode), @@ -143,10 +145,16 @@ class Tools: args.extend(('--iv', iv)) return args - def run_encrypt_file(self, algorithm, mode, key, input_path, output_path, iv=None): - return self.run(self._ENCRYPT_FILE, - self._file_settings_to_args(algorithm, mode, key, input_path, output_path, iv)) + def run_encrypt_file( + self, algorithm, mode, key, input_path, output_path, iv=None): + + args = self._build_file_args( + algorithm, mode, key, input_path, output_path, iv) + return self.run(self._ENCRYPT_FILE, args) + + def run_decrypt_file( + self, algorithm, mode, key, input_path, output_path, iv=None): - def run_decrypt_file(self, algorithm, mode, key, input_path, output_path, iv=None): - return self.run(self._DECRYPT_FILE, - self._file_settings_to_args(algorithm, mode, key, input_path, output_path, iv)) + args = self._build_file_args( + algorithm, mode, key, input_path, output_path, iv) + return self.run(self._DECRYPT_FILE, args) |