mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-06-05 21:15:09 +00:00
tests: pk_helpers: optimize failure reporting in mbedtls_pk_helpers_populate_context
Keep TEST_EQUAL() on the function that might fail so that if a failure happen the message will report the actual function that failed. Documentation of the helper function is also updated. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This commit is contained in:
@@ -74,7 +74,9 @@ mbedtls_svc_key_id_t mbedtls_pk_helpers_make_psa_key_from_predefined(psa_key_typ
|
||||
* \param method The desired method for populating the PK context. See
|
||||
* "pk_context_populate_method_t" for available options.
|
||||
*
|
||||
* \return 0 on success; an error code otherwise.
|
||||
* \return 0 on success.
|
||||
* In case of failure -1 is returned and the test case is marked
|
||||
* as failed.
|
||||
*/
|
||||
int mbedtls_pk_helpers_populate_context(mbedtls_pk_context *pk, mbedtls_svc_key_id_t key_id,
|
||||
pk_context_populate_method_t method);
|
||||
|
||||
@@ -109,23 +109,23 @@ exit:
|
||||
int mbedtls_pk_helpers_populate_context(mbedtls_pk_context *pk, mbedtls_svc_key_id_t key_id,
|
||||
pk_context_populate_method_t method)
|
||||
{
|
||||
int ret;
|
||||
int ret = -1;
|
||||
|
||||
switch (method) {
|
||||
case TEST_PK_WRAP_PSA:
|
||||
ret = mbedtls_pk_wrap_psa(pk, key_id);
|
||||
TEST_EQUAL(mbedtls_pk_wrap_psa(pk, key_id), 0);
|
||||
break;
|
||||
case TEST_PK_COPY_FROM_PSA:
|
||||
ret = mbedtls_pk_copy_from_psa(key_id, pk);
|
||||
TEST_EQUAL(mbedtls_pk_copy_from_psa(key_id, pk), 0);
|
||||
break;
|
||||
case TEST_PK_COPY_PUBLIC_FROM_PSA:
|
||||
ret = mbedtls_pk_copy_public_from_psa(key_id, pk);
|
||||
TEST_EQUAL(mbedtls_pk_copy_public_from_psa(key_id, pk), 0);
|
||||
break;
|
||||
default:
|
||||
ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
|
||||
TEST_FAIL("Unknown population method");
|
||||
}
|
||||
|
||||
TEST_EQUAL(ret, 0);
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user