@@ -126,16 +126,16 @@ def test_wrap(self):
126
126
key2 [pkcs11 .Attribute .VALUE ])
127
127
128
128
@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 ),
135
135
])
136
136
@requires (Mechanism .AES_ECB_ENCRYPT_DATA )
137
137
@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 ):
139
139
"""Function to test AES Key Derivation using the ECB_ENCRYPT Mechanism.
140
140
141
141
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):
169
169
pkcs11 .exceptions .FunctionFailed ) as e :
170
170
derived_key = None
171
171
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 ))
176
173
177
174
@parameterized .expand ([
178
175
("POSITIVE_128_BIT" , 128 , 16 ),
@@ -229,19 +226,19 @@ def test_encrypt_with_key_derived_using_ecb_encrypt(self, test_type, test_key_le
229
226
self .assertEqual (text , data )
230
227
231
228
@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 ),
241
238
])
242
239
@requires (Mechanism .AES_CBC_ENCRYPT_DATA )
243
240
@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 ):
245
242
"""Function to test AES Key Derivation using the CBC_ENCRYPT Mechanism.
246
243
247
244
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
277
274
IndexError ) as e :
278
275
derived_key = None
279
276
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 ))
284
278
285
279
@parameterized .expand ([
286
280
("POSITIVE_128_BIT" , 128 , 16 , 16 ),
0 commit comments