Commits

Jason R. Coombs  committed b9525cf

Expanded tests to test all cipher algorithms and modes

  • Participants
  • Parent commits 30f8f99

Comments (0)

Files changed (1)

File tests/test_cipher.py

+import itertools
 from ctypescrypto import cipher
 
-def test_cipher_type():
+def test_cipher_type(algorithm, mode):
 	# One can pass the algorithm and mode separately or together
-	t = cipher.CipherType.from_name('AES-256', 'CBC')
-	t = cipher.CipherType.from_name('AES-256-CBC')
+	t = cipher.CipherType.from_name(algorithm, mode)
+	t = cipher.CipherType.from_name(algorithm + '-' + mode)
 
 def pytest_generate_tests(metafunc):
 	if "data_parts" in metafunc.funcargnames:
 			metafunc.addcall(funcargs=dict(
 				data_parts=('a'*i, 'b'*i, 'c'*i)
 				))
+	if metafunc.funcargnames == ['algorithm', 'mode']:
+		pairs = itertools.product(cipher.CIPHER_ALGORITHMS,
+			cipher.CIPHER_MODES)
+		for algorithm, mode in pairs:
+			# apparently DES-EDE3-ECB is not a valid mode
+			if (algorithm, mode) == ('DES-EDE3', 'ECB'): continue
+			metafunc.addcall(funcargs=dict(
+				algorithm=algorithm, mode=mode
+				))
 
 def test_cipher(data_parts):
 	"""