Use switch-case for error handling

Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
gabor-mezei-arm 2021-05-03 16:30:53 +02:00
parent 6dcaa3b5a1
commit 6cdf637f88
No known key found for this signature in database
GPG key ID: 106F5A41ECC305BD

View file

@ -2489,21 +2489,26 @@ static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key,
*signature_length = 0; *signature_length = 0;
if( operation == PSA_SIGN_INVALID ) switch( operation )
return( PSA_ERROR_INVALID_ARGUMENT );
else
{ {
if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) ) case PSA_SIGN_HASH:
return( PSA_ERROR_INVALID_ARGUMENT ); if( ! PSA_ALG_IS_HASH_AND_SIGN( alg ) )
return( PSA_ERROR_INVALID_ARGUMENT );
break;
case PSA_SIGN_MESSAGE:
if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) )
return( PSA_ERROR_INVALID_ARGUMENT );
if( operation == PSA_SIGN_MESSAGE )
{
if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) ) if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) )
{ {
if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) ) if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) )
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
} break;
default:
return( PSA_ERROR_INVALID_ARGUMENT );
} }
/* Immediately reject a zero-length signature buffer. This guarantees /* Immediately reject a zero-length signature buffer. This guarantees
@ -2579,21 +2584,26 @@ static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key,
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
psa_key_slot_t *slot; psa_key_slot_t *slot;
if( operation == PSA_VERIFY_INVALID ) switch( operation )
return( PSA_ERROR_INVALID_ARGUMENT );
else
{ {
if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) ) case PSA_VERIFY_HASH:
return( PSA_ERROR_INVALID_ARGUMENT ); if( ! PSA_ALG_IS_HASH_AND_SIGN( alg ) )
return( PSA_ERROR_INVALID_ARGUMENT );
break;
case PSA_VERIFY_MESSAGE:
if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) )
return( PSA_ERROR_INVALID_ARGUMENT );
if( operation == PSA_VERIFY_MESSAGE )
{
if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) ) if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) )
{ {
if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) ) if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) )
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
} break;
default:
return( PSA_ERROR_INVALID_ARGUMENT );
} }
status = psa_get_and_lock_key_slot_with_policy( status = psa_get_and_lock_key_slot_with_policy(