diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-08 23:40:11 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-08 23:40:11 +0300 |
commit | 6541ca090361af2811f69d74df0d0854f3ba2922 (patch) | |
tree | 982283aac09abd48b5c8a035eaf45b8ffce53876 /test | |
parent | test/800-38a.py: bugfix (diff) | |
download | aes-tools-6541ca090361af2811f69d74df0d0854f3ba2922.tar.gz aes-tools-6541ca090361af2811f69d74df0d0854f3ba2922.zip |
test: refactoring
* Test vectors are now stored in the Python script rather than in a JSON
file.
* The tests are now really Python's unittest `TestCase`s, allowing (at
least in the future) to discover and run them automatically.
* Use logging from the standard library for logging.
* Bugfix & refactoring.
Diffstat (limited to '')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/800-38a.json | 239 | ||||
-rw-r--r-- | test/800-38a.py | 155 | ||||
-rw-r--r-- | test/README.md | 5 | ||||
-rw-r--r-- | test/toolkit.py | 103 |
5 files changed, 189 insertions, 314 deletions
diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..397b4a7 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +*.log diff --git a/test/800-38a.json b/test/800-38a.json deleted file mode 100644 index 66511eb..0000000 --- a/test/800-38a.json +++ /dev/null @@ -1,239 +0,0 @@ -{ - "aes128ecb": { - "key": "2b7e151628aed2a6abf7158809cf4f3c", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "3ad77bb40d7a3660a89ecaf32466ef97", - "f5d3d58503b9699de785895a96fdbaaf", - "43b1cd7f598ece23881b00e3ed030688", - "7b0c785e27e8ad3f8223207104725dd4" - ] - }, - "aes128cbc": { - "key": "2b7e151628aed2a6abf7158809cf4f3c", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "7649abac8119b246cee98e9b12e9197d", - "5086cb9b507219ee95db113a917678b2", - "73bed6b8e3c1743b7116e69e22229516", - "3ff1caa1681fac09120eca307586e1a7" - ] - }, - "aes128cfb": { - "key": "2b7e151628aed2a6abf7158809cf4f3c", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "3b3fd92eb72dad20333449f8e83cfb4a", - "c8a64537a0b3a93fcde3cdad9f1ce58b", - "26751f67a3cbb140b1808cf187a4f4df", - "c04b05357c5d1c0eeac4c66f9ff7f2e6" - ] - }, - "aes128ofb": { - "key": "2b7e151628aed2a6abf7158809cf4f3c", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "3b3fd92eb72dad20333449f8e83cfb4a", - "7789508d16918f03f53c52dac54ed825", - "9740051e9c5fecf64344f7a82260edcc", - "304c6528f659c77866a510d9c1d6ae5e" - ] - }, - "aes128ctr": { - "key": "2b7e151628aed2a6abf7158809cf4f3c", - "iv": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "874d6191b620e3261bef6864990db6ce", - "9806f66b7970fdff8617187bb9fffdff", - "5ae4df3edbd5d35e5b4f09020db03eab", - "1e031dda2fbe03d1792170a0f3009cee" - ] - }, - "aes192ecb": { - "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "bd334f1d6e45f25ff712a214571fa5cc", - "974104846d0ad3ad7734ecb3ecee4eef", - "ef7afd2270e2e60adce0ba2face6444e", - "9a4b41ba738d6c72fb16691603c18e0e" - ] - }, - "aes192cbc": { - "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "4f021db243bc633d7178183a9fa071e8", - "b4d9ada9ad7dedf4e5e738763f69145a", - "571b242012fb7ae07fa9baac3df102e0", - "08b0e27988598881d920a9e64f5615cd" - ] - }, - "aes192cfb": { - "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "cdc80d6fddf18cab34c25909c99a4174", - "67ce7f7f81173621961a2b70171d3d7a", - "2e1e8a1dd59b88b1c8e60fed1efac4c9", - "c05f9f9ca9834fa042ae8fba584b09ff" - ] - }, - "aes192ofb": { - "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "cdc80d6fddf18cab34c25909c99a4174", - "fcc28b8d4c63837c09e81700c1100401", - "8d9a9aeac0f6596f559c6d4daf59a5f2", - "6d9f200857ca6c3e9cac524bd9acc92a" - ] - }, - "aes192ctr": { - "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", - "iv": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "1abc932417521ca24f2b0459fe7e6e0b", - "090339ec0aa6faefd5ccc2c6f4ce8e94", - "1e36b26bd1ebc670d1bd1d665620abf7", - "4f78a7f6d29809585a97daec58c6b050" - ] - }, - "aes256ecb": { - "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "f3eed1bdb5d2a03c064b5a7e3db181f8", - "591ccb10d410ed26dc5ba74a31362870", - "b6ed21b99ca6f4f9f153e7b1beafed1d", - "23304b7a39f9f3ff067d8d8f9e24ecc7" - ] - }, - "aes256cbc": { - "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "f58c4c04d6e5f1ba779eabfb5f7bfbd6", - "9cfc4e967edb808d679f777bc6702c7d", - "39f23369a9d9bacfa530e26304231461", - "b2eb05e2c39be9fcda6c19078c6a9d1b" - ] - }, - "aes256cfb": { - "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "dc7e84bfda79164b7ecd8486985d3860", - "39ffed143b28b1c832113c6331e5407b", - "df10132415e54b92a13ed0a8267ae2f9", - "75a385741ab9cef82031623d55b1e471" - ] - }, - "aes256ofb": { - "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", - "iv": "000102030405060708090a0b0c0d0e0f", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "dc7e84bfda79164b7ecd8486985d3860", - "4febdc6740d20b3ac88f6ad82a4fb08d", - "71ab47a086e86eedf39d1c5bba97c408", - "0126141d67f37be8538f5a8be740e484" - ] - }, - "aes256ctr": { - "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", - "iv": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "plaintexts": [ - "6bc1bee22e409f96e93d7e117393172a", - "ae2d8a571e03ac9c9eb76fac45af8e51", - "30c81c46a35ce411e5fbc1191a0a52ef", - "f69f2445df4f9b17ad2b417be66c3710" - ], - "ciphers": [ - "601ec313775789a5b7a7f504bbf3d228", - "f443e3ca4d62b59aca84e990cacaf5c5", - "2b0930daa23de94ce87017ba2d84988d", - "dfc9c58db67aada613c2dd08457941a6" - ] - } -} diff --git a/test/800-38a.py b/test/800-38a.py index a929696..d99fa4a 100644 --- a/test/800-38a.py +++ b/test/800-38a.py @@ -2,32 +2,141 @@ # This file is licensed under the terms of the MIT License. # See LICENSE.txt for details. +import toolkit, unittest + +_plaintexts = ['6bc1bee22e409f96e93d7e117393172a', + 'ae2d8a571e03ac9c9eb76fac45af8e51', + '30c81c46a35ce411e5fbc1191a0a52ef', + 'f69f2445df4f9b17ad2b417be66c3710'] + +_keys = {toolkit.AES128: '2b7e151628aed2a6abf7158809cf4f3c', + toolkit.AES192: '8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b', + toolkit.AES256: '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4'} + +_default_iv = '000102030405060708090a0b0c0d0e0f' +_ctr_iv = 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff' + +_init_vectors = {toolkit.AES128: {toolkit.CBC: _default_iv, + toolkit.CFB: _default_iv, + toolkit.OFB: _default_iv, + toolkit.CTR: _ctr_iv}} +_init_vectors[toolkit.AES192] = _init_vectors[toolkit.AES128] +_init_vectors[toolkit.AES256] = _init_vectors[toolkit.AES128] + +_ciphertexts = {toolkit.AES128: {toolkit.ECB: ['3ad77bb40d7a3660a89ecaf32466ef97', + 'f5d3d58503b9699de785895a96fdbaaf', + '43b1cd7f598ece23881b00e3ed030688', + '7b0c785e27e8ad3f8223207104725dd4'], + toolkit.CBC: ['7649abac8119b246cee98e9b12e9197d', + '5086cb9b507219ee95db113a917678b2', + '73bed6b8e3c1743b7116e69e22229516', + '3ff1caa1681fac09120eca307586e1a7'], + toolkit.CFB: ['3b3fd92eb72dad20333449f8e83cfb4a', + 'c8a64537a0b3a93fcde3cdad9f1ce58b', + '26751f67a3cbb140b1808cf187a4f4df', + 'c04b05357c5d1c0eeac4c66f9ff7f2e6'], + toolkit.OFB: ['3b3fd92eb72dad20333449f8e83cfb4a', + '7789508d16918f03f53c52dac54ed825', + '9740051e9c5fecf64344f7a82260edcc', + '304c6528f659c77866a510d9c1d6ae5e'], + toolkit.CTR: ['874d6191b620e3261bef6864990db6ce', + '9806f66b7970fdff8617187bb9fffdff', + '5ae4df3edbd5d35e5b4f09020db03eab', + '1e031dda2fbe03d1792170a0f3009cee']}, + toolkit.AES192: {toolkit.ECB: ['bd334f1d6e45f25ff712a214571fa5cc', + '974104846d0ad3ad7734ecb3ecee4eef', + 'ef7afd2270e2e60adce0ba2face6444e', + '9a4b41ba738d6c72fb16691603c18e0e'], + toolkit.CBC: ['4f021db243bc633d7178183a9fa071e8', + 'b4d9ada9ad7dedf4e5e738763f69145a', + '571b242012fb7ae07fa9baac3df102e0', + '08b0e27988598881d920a9e64f5615cd'], + toolkit.CFB: ['cdc80d6fddf18cab34c25909c99a4174', + '67ce7f7f81173621961a2b70171d3d7a', + '2e1e8a1dd59b88b1c8e60fed1efac4c9', + 'c05f9f9ca9834fa042ae8fba584b09ff'], + toolkit.OFB: ['cdc80d6fddf18cab34c25909c99a4174', + 'fcc28b8d4c63837c09e81700c1100401', + '8d9a9aeac0f6596f559c6d4daf59a5f2', + '6d9f200857ca6c3e9cac524bd9acc92a'], + toolkit.CTR: ['1abc932417521ca24f2b0459fe7e6e0b', + '090339ec0aa6faefd5ccc2c6f4ce8e94', + '1e36b26bd1ebc670d1bd1d665620abf7', + '4f78a7f6d29809585a97daec58c6b050']}, + toolkit.AES256: {toolkit.ECB: ['f3eed1bdb5d2a03c064b5a7e3db181f8', + '591ccb10d410ed26dc5ba74a31362870', + 'b6ed21b99ca6f4f9f153e7b1beafed1d', + '23304b7a39f9f3ff067d8d8f9e24ecc7'], + toolkit.CBC: ['f58c4c04d6e5f1ba779eabfb5f7bfbd6', + '9cfc4e967edb808d679f777bc6702c7d', + '39f23369a9d9bacfa530e26304231461', + 'b2eb05e2c39be9fcda6c19078c6a9d1b'], + toolkit.CFB: ['dc7e84bfda79164b7ecd8486985d3860', + '39ffed143b28b1c832113c6331e5407b', + 'df10132415e54b92a13ed0a8267ae2f9', + '75a385741ab9cef82031623d55b1e471'], + toolkit.OFB: ['dc7e84bfda79164b7ecd8486985d3860', + '4febdc6740d20b3ac88f6ad82a4fb08d', + '71ab47a086e86eedf39d1c5bba97c408', + '0126141d67f37be8538f5a8be740e484'], + toolkit.CTR: ['601ec313775789a5b7a7f504bbf3d228', + 'f443e3ca4d62b59aca84e990cacaf5c5', + '2b0930daa23de94ce87017ba2d84988d', + 'dfc9c58db67aada613c2dd08457941a6']}} + +def _parametrize(cls, tools, algo, mode): + testloader = unittest.TestLoader() + testnames = testloader.getTestCaseNames(cls) + suite = unittest.TestSuite() + for name in testnames: + suite.addTest(cls(name, tools, algo, mode)) + return suite + +class TestAlgorithm(unittest.TestCase): + def __init__(self, methodName='runTest', tools=None, algo=None, mode=None): + super(TestAlgorithm, self).__init__(methodName) + self._tools = tools + self._algo = algo + self._mode = mode + + def test_encrypt(self): + key = _keys[self._algo] + iv = None + if self._algo in _init_vectors and self._mode in _init_vectors[self._algo]: + iv = _init_vectors[self._algo][self._mode] + ciphertexts = _ciphertexts[self._algo][self._mode] + input = toolkit.EncryptionInput(key, _plaintexts, iv=iv) + self.assertEqual(ciphertexts, self._tools.run_encrypt_tool(self._algo, self._mode, input)) + + def test_decrypt(self): + key = _keys[self._algo] + iv = None + if self._algo in _init_vectors and self._mode in _init_vectors[self._algo]: + iv = _init_vectors[self._algo][self._mode] + ciphertexts = _ciphertexts[self._algo][self._mode] + input = toolkit.DecryptionInput(key, ciphertexts, iv=iv) + self.assertEqual(_plaintexts, self._tools.run_decrypt_tool(self._algo, self._mode, input)) + if __name__ == '__main__': - import argparse, json, toolkit, sys - parser = argparse.ArgumentParser() + import argparse + parser = argparse.ArgumentParser(add_help=False) parser.add_argument('--root', '-r', required=True, help='set path to *.exe files') parser.add_argument('--sde', '-e', action='store_true', help='use Intel SDE to run *.exe files') - args = parser.parse_args() - tools = toolkit.Tools(args.root, use_sde=args.sde) - vectors = json.load(open('800-38a.json')) - success = True - for prefix in vectors: - if 'iv' in vectors[prefix]: - iv = vectors[prefix]['iv'] - encrypt = lambda key, plaintexts: tools.encrypt_with_iv(prefix, key, iv, plaintexts) - decrypt = lambda key, ciphers: tools.decrypt_with_iv(prefix, key, iv, ciphers) - else: - encrypt = lambda key, plaintexts: tools.encrypt(prefix, key, plaintexts) - decrypt = lambda key, ciphers: tools.decrypt(prefix, key, ciphers) - key = vectors[prefix]['key'] - plaintexts = vectors[prefix]['plaintexts'] - ciphers = vectors[prefix]['ciphers'] - success = tools.detect_mismatches(plaintexts, encrypt(key, plaintexts), ciphers) and success - success = tools.detect_mismatches(ciphers, decrypt(key, ciphers), plaintexts) and success - if success: - print('No mismatches detected!') + parser.add_argument('--log', '-l', help='set log file path') + args, _ = parser.parse_known_args() + + tools = toolkit.Tools(args.root, args.sde) + + import logging, logging.handlers + if args.log is None: + logging.getLogger().addHandler(logging.NullHandler()) else: - print('Detected mismatches!') - sys.exit(1) + logging.basicConfig(filename=args.log, format='%(asctime)s | %(module)s | %(message)s', level=logging.INFO) + + suite = unittest.TestSuite() + for algo in _ciphertexts: + for mode in _ciphertexts[algo]: + suite.addTest(_parametrize(TestAlgorithm, tools, algo, mode)) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/README.md b/test/README.md index f49979a..b195db6 100644 --- a/test/README.md +++ b/test/README.md @@ -55,5 +55,6 @@ using python 800-32a.py -r C:\build\test\Debug -e -I've tried to make the script output self-explanatory. -The ultimate goal is to get `No mismatches detected!` in the final line. +You can investigate what went wrong (if it did) by logging calls to the `*_encrypt.exe` and `*_decrypt.exe` utilities by passing the `--log/-l FILENAME` option to the script. + +The tests are really Python's `unittest` `TestCase`s, so the output of the script should be self-explanatory and familiary to users with prior Python testing experience. diff --git a/test/toolkit.py b/test/toolkit.py index 1a5859b..a69ce73 100644 --- a/test/toolkit.py +++ b/test/toolkit.py @@ -2,62 +2,65 @@ # This file is licensed under the terms of the MIT License. # See LICENSE.txt for details. +import logging import os.path import subprocess import sys +AES128, AES192, AES256 = 'aes128', 'aes192', 'aes256' +ECB, CBC, CFB, OFB, CTR = 'ecb', 'cbc', 'cfb', 'ofb', 'ctr' + +class EncryptionInput: + def __init__(self, key, plaintexts, iv=None): + self.key = key + self.plaintexts = plaintexts + self.iv = iv + + def to_args(self): + args = [self.key] + if self.iv is not None: + args.append(self.iv) + args.extend(self.plaintexts) + return args + +class DecryptionInput: + def __init__(self, key, ciphertexts, iv=None): + self.key = key + self.ciphertexts = ciphertexts + self.iv = iv + + def to_args(self): + args = [self.key] + if self.iv is not None: + args.append(self.iv) + args.extend(self.ciphertexts) + return args + class Tools: def __init__(self, root_dir_path, use_sde=False): self._root_dir_path = root_dir_path self._use_sde = use_sde + self._logger = logging.getLogger(__name__) + + def _get_tool_path(self, fn): + return os.path.join(self._root_dir_path, fn) + + def get_encrypt_tool_path(self, algo, mode): + return self._get_tool_path('{0}{1}_encrypt.exe'.format(algo, mode)) + + def get_decrypt_tool_path(self, algo, mode): + return self._get_tool_path('{0}{1}_decrypt.exe'.format(algo, mode)) + + def run_tool(self, tool_path, args): + cmd_list = ['sde', '--', tool_path] if self._use_sde else [tool_path] + cmd_list.extend(args) + logging.info('Trying to execute: {0}'.format(subprocess.list2cmdline(cmd_list))) + output = subprocess.check_output(cmd_list, universal_newlines=True) + logging.info('Output:\n' + output) + return output.split() + + def run_encrypt_tool(self, algo, mode, input): + return self.run_tool(self.get_encrypt_tool_path(algo, mode), input.to_args()) - def _get_tool_path(self, tool_name): - return os.path.join(self._root_dir_path, tool_name) - - def _get_encrypt_tool_path(self, prefix): - return self._get_tool_path('{0}_encrypt.exe'.format(prefix)) - - def _get_decrypt_tool_path(self, prefix): - return self._get_tool_path('{0}_decrypt.exe'.format(prefix)) - - def _capture_tool_output(self, tool_path, args): - with_sde = ['sde', '--', tool_path] if self._use_sde else [tool_path] - return subprocess.check_output(with_sde + args, universal_newlines=True).split() - - def encrypt(self, prefix, key, args): - print('Encrypting using \'{0}\'...'.format(prefix)) - print('\tKey:', key) - return self._capture_tool_output(self._get_encrypt_tool_path(prefix), [key] + args) - - def decrypt(self, prefix, key, args): - print('Decrypting using \'{0}\'...'.format(prefix)) - print('\tKey:', key) - return self._capture_tool_output(self._get_decrypt_tool_path(prefix), [key] + args) - - def encrypt_with_iv(self, prefix, key, iv, args): - print('Encrypting using \'{0}\'...'.format(prefix)) - print('\tKey:', key) - print('\tInitialization vector:', iv) - return self._capture_tool_output(self._get_encrypt_tool_path(prefix), [key, iv] + args) - - def decrypt_with_iv(self, prefix, key, iv, args): - print('Decrypting using \'{0}\'...'.format(prefix)) - print('\tKey:', key) - print('\tInitialization vector:', iv) - return self._capture_tool_output(self._get_decrypt_tool_path(prefix), [key, iv] + args) - - def detect_mismatches(self, input, actual_output, expected_output): - if len(actual_output) != len(expected_output): - print('Unexpected output length!', file=sys.stderr) - print('\tExpected length:', len(expected_output), file=sys.stderr) - print('\tActual length:', len(actual_output), file=sys.stderr) - return False - no_mismatches = True - for i in range(len(input)): - if actual_output[i] != expected_output[i]: - print('A mismatch detected!', file=sys.stderr) - print('\tInput:', input[i], file=sys.stderr) - print('\tExpected:', expected_output[i], file=sys.stderr) - print('\tActual:', actual_output[i], file=sys.stderr) - no_mismatches = False - return no_mismatches + def run_decrypt_tool(self, algo, mode, input): + return self.run_tool(self.get_decrypt_tool_path(algo, mode), input.to_args()) |