Remove key generation when given argument is invalid from NotSupported class

Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemyslaw Stekiel 2021-10-18 14:58:20 +02:00
parent 997caf835c
commit 32a8b84814
2 changed files with 6 additions and 55 deletions

View file

@ -149,30 +149,8 @@ def test_case_for_key_type_not_supported(
tc.set_arguments([key_type] + list(args)) tc.set_arguments([key_type] + list(args))
return tc return tc
def test_case_for_key_type_invalid_argument(
verb: str, key_type: str, bits: int,
dependencies: List[str],
*args: str,
param_descr: str = ''
) -> test_case.TestCase:
"""Return one test case exercising a key creation method
for an invalid argument when key is public.
"""
hack_dependencies_not_implemented(dependencies)
tc = test_case.TestCase()
short_key_type = re.sub(r'PSA_(KEY_TYPE|ECC_FAMILY)_', r'', key_type)
adverb = 'not' if dependencies else 'never'
if param_descr:
adverb = param_descr + ' ' + adverb
tc.set_description('PSA {} {} {}-bit invalid argument'
.format(verb, short_key_type, bits))
tc.set_function(verb + '_invalid_argument')
tc.set_dependencies(dependencies)
tc.set_arguments([key_type] + list(args))
return tc
class NotSupported: class NotSupported:
"""Generate test cases for when something is not supported or argument is inavlid.""" """Generate test cases for when something is not supported."""
def __init__(self, info: Information) -> None: def __init__(self, info: Information) -> None:
self.constructors = info.constructors self.constructors = info.constructors
@ -187,13 +165,11 @@ class NotSupported:
param: Optional[int] = None, param: Optional[int] = None,
param_descr: str = '', param_descr: str = '',
) -> Iterator[test_case.TestCase]: ) -> Iterator[test_case.TestCase]:
"""Return test cases exercising key creation when the given type is unsupported """Return test cases exercising key creation when the given type is unsupported.
or argument is invalid.
If param is present and not None, emit test cases conditioned on this If param is present and not None, emit test cases conditioned on this
parameter not being supported. If it is absent or None, emit test cases parameter not being supported. If it is absent or None, emit test cases
conditioned on the base type not being supported. If key is public emit test conditioned on the base type not being supported.
case for invalid argument.
""" """
if kt.name in self.ALWAYS_SUPPORTED: if kt.name in self.ALWAYS_SUPPORTED:
# Don't generate test cases for key types that are always supported. # Don't generate test cases for key types that are always supported.
@ -221,14 +197,8 @@ class NotSupported:
# supported or not depending on implementation capabilities, # supported or not depending on implementation capabilities,
# only generate the test case once. # only generate the test case once.
continue continue
if kt.name.endswith('_PUBLIC_KEY'): # Public key cannot be generated
yield test_case_for_key_type_invalid_argument( if not kt.name.endswith('_PUBLIC_KEY'):
'generate', kt.expression, bits,
finish_family_dependencies(generate_dependencies, bits),
str(bits),
param_descr=param_descr,
)
else:
yield test_case_for_key_type_not_supported( yield test_case_for_key_type_not_supported(
'generate', kt.expression, bits, 'generate', kt.expression, bits,
finish_family_dependencies(generate_dependencies, bits), finish_family_dependencies(generate_dependencies, bits),
@ -260,7 +230,7 @@ def test_case_for_key_generation(
dependencies: List[str], dependencies: List[str],
*args: str, *args: str,
result: str = '', result: str = '',
param_descr: str = '', param_descr: str = ''
) -> test_case.TestCase: ) -> test_case.TestCase:
"""Return one test case exercising a key generation. """Return one test case exercising a key generation.
""" """

View file

@ -50,22 +50,3 @@ exit:
PSA_DONE( ); PSA_DONE( );
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */
void generate_invalid_argument( int key_type, int bits )
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
PSA_ASSERT( psa_crypto_init( ) );
psa_set_key_type( &attributes, key_type );
psa_set_key_bits( &attributes, bits );
TEST_EQUAL( psa_generate_key( &attributes, &key_id ),
PSA_ERROR_INVALID_ARGUMENT );
TEST_ASSERT( mbedtls_svc_key_id_equal( key_id, MBEDTLS_SVC_KEY_ID_INIT ) );
exit:
psa_destroy_key( key_id );
PSA_DONE( );
}
/* END_CASE */