@@ -126,16 +126,16 @@ def test_wrap(self):
126126 key2 [pkcs11 .Attribute .VALUE ])
127127
128128 @parameterized .expand ([
129- ("POSITIVE_128_BIT" , 128 , 16 ),
130- ("POSITIVE_128_BIT_LONG_IV" , 128 , 32 ),
131- ("NEGATIVE_128_BIT_BAD_IV" , 128 , 15 ),
132- ("POSITIVE_256_BIT_LONG_IV" , 256 , 32 ),
133- ("NEGATIVE_256_BIT_SHORT_IV" , 256 , 16 ),
134- ("NEGATIVE_256_BIT_BAD_IV" , 256 , 31 ),
129+ ("POSITIVE_128_BIT" , 128 , 16 , TestCase . assertIsNotNone ),
130+ ("POSITIVE_128_BIT_LONG_IV" , 128 , 32 , TestCase . assertIsNotNone ),
131+ ("NEGATIVE_128_BIT_BAD_IV" , 128 , 15 , TestCase . assertIsNone ),
132+ ("POSITIVE_256_BIT_LONG_IV" , 256 , 32 , TestCase . assertIsNotNone ),
133+ ("NEGATIVE_256_BIT_SHORT_IV" , 256 , 16 , TestCase . assertIsNone ),
134+ ("NEGATIVE_256_BIT_BAD_IV" , 256 , 31 , TestCase . assertIsNone ),
135135 ])
136136 @requires (Mechanism .AES_ECB_ENCRYPT_DATA )
137137 @FIXME .opencryptoki # can't set key attributes
138- def test_derive_using_ecb_encrypt (self , test_type , test_key_length , iv_length ):
138+ def test_derive_using_ecb_encrypt (self , test_type , test_key_length , iv_length , assert_fn ):
139139 """Function to test AES Key Derivation using the ECB_ENCRYPT Mechanism.
140140
141141 Refer to Section 2.15 of http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850521
@@ -169,10 +169,7 @@ def test_derive_using_ecb_encrypt(self, test_type, test_key_length, iv_length):
169169 pkcs11 .exceptions .FunctionFailed ) as e :
170170 derived_key = None
171171
172- if test_type .startswith ("NEGATIVE" ):
173- self .assertTrue (derived_key is None , "Unexpected {}-bit Derived Key" .format (test_key_length ))
174- else :
175- self .assertTrue (derived_key is not None , "Failed to derive {}-bit Derived Key" .format (test_key_length ))
172+ assert_fn (self , derived_key , "{}-bit Key Derivation Failure" .format (test_key_length ))
176173
177174 @parameterized .expand ([
178175 ("POSITIVE_128_BIT" , 128 , 16 ),
@@ -229,19 +226,19 @@ def test_encrypt_with_key_derived_using_ecb_encrypt(self, test_type, test_key_le
229226 self .assertEqual (text , data )
230227
231228 @parameterized .expand ([
232- ("POSITIVE_128_BIT" , 128 , 16 , 16 ),
233- ("POSITIVE_128_BIT_LONG_DATA" , 128 , 16 , 64 ),
234- ("NEGATIVE_128_BIT_BAD_IV" , 128 , 15 , 16 ),
235- ("NEGATIVE_128_BIT_BAD_DATA" , 128 , 16 , 31 ),
236- ("POSITIVE_256_BIT" , 256 , 16 , 32 ),
237- ("POSITIVE_256_BIT_LONG_DATA" , 256 , 16 , 64 ),
238- ("NEGATIVE_256_BIT_BAD_IV" , 256 , 15 , 16 ),
239- ("NEGATIVE_256_BIT_BAD_DATA" , 256 , 16 , 31 ),
240- ("NEGATIVE_256_BIT_SHORT_DATA" , 256 , 16 , 16 ),
229+ ("POSITIVE_128_BIT" , 128 , 16 , 16 , TestCase . assertIsNotNone ),
230+ ("POSITIVE_128_BIT_LONG_DATA" , 128 , 16 , 64 , TestCase . assertIsNotNone ),
231+ ("NEGATIVE_128_BIT_BAD_IV" , 128 , 15 , 16 , TestCase . assertIsNone ),
232+ ("NEGATIVE_128_BIT_BAD_DATA" , 128 , 16 , 31 , TestCase . assertIsNone ),
233+ ("POSITIVE_256_BIT" , 256 , 16 , 32 , TestCase . assertIsNotNone ),
234+ ("POSITIVE_256_BIT_LONG_DATA" , 256 , 16 , 64 , TestCase . assertIsNotNone ),
235+ ("NEGATIVE_256_BIT_BAD_IV" , 256 , 15 , 16 , TestCase . assertIsNone ),
236+ ("NEGATIVE_256_BIT_BAD_DATA" , 256 , 16 , 31 , TestCase . assertIsNone ),
237+ ("NEGATIVE_256_BIT_SHORT_DATA" , 256 , 16 , 16 , TestCase . assertIsNone ),
241238 ])
242239 @requires (Mechanism .AES_CBC_ENCRYPT_DATA )
243240 @FIXME .opencryptoki # can't set key attributes
244- def test_derive_using_cbc_encrypt (self , test_type , test_key_length , iv_length , data_length ):
241+ def test_derive_using_cbc_encrypt (self , test_type , test_key_length , iv_length , data_length , assert_fn ):
245242 """Function to test AES Key Derivation using the CBC_ENCRYPT Mechanism.
246243
247244 Refer to Section 2.15 of http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850521
@@ -277,10 +274,7 @@ def test_derive_using_cbc_encrypt(self, test_type, test_key_length, iv_length, d
277274 IndexError ) as e :
278275 derived_key = None
279276
280- if test_type .startswith ("NEGATIVE" ):
281- self .assertTrue (derived_key is None , "Unexpected {}-bit Derived Key" .format (test_key_length ))
282- else :
283- self .assertTrue (derived_key is not None , "Failed to derive {}-bit Derived Key" .format (test_key_length ))
277+ assert_fn (self , derived_key , "{}-bit Key Derivation Failure" .format (test_key_length ))
284278
285279 @parameterized .expand ([
286280 ("POSITIVE_128_BIT" , 128 , 16 , 16 ),
0 commit comments