diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 3b9eada83..c269280bf 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -643,12 +643,21 @@ void invalid_handle( ) TEST_ASSERT( handle1 != 0 ); /* Attempt to close and destroy some invalid handles. */ - TEST_EQUAL( psa_close_key( 0 ), PSA_ERROR_INVALID_HANDLE ); - TEST_EQUAL( psa_close_key( handle1 - 1 ), PSA_ERROR_INVALID_HANDLE ); - TEST_EQUAL( psa_close_key( handle1 + 1 ), PSA_ERROR_INVALID_HANDLE ); - TEST_EQUAL( psa_destroy_key( 0 ), PSA_ERROR_INVALID_HANDLE ); - TEST_EQUAL( psa_destroy_key( handle1 - 1 ), PSA_ERROR_INVALID_HANDLE ); - TEST_EQUAL( psa_destroy_key( handle1 + 1 ), PSA_ERROR_INVALID_HANDLE ); + if( handle1 - 1 != 0 ) + { + TEST_EQUAL( psa_close_key( handle1 - 1 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_destroy_key( handle1 - 1 ), PSA_ERROR_INVALID_HANDLE ); + } + if( handle1 + 1 != 0 ) + { + TEST_EQUAL( psa_close_key( handle1 + 1 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_destroy_key( handle1 + 1 ), PSA_ERROR_INVALID_HANDLE ); + } + + /* 0 is special: it isn't a valid handle, but close/destroy + * succeeds on it. */ + TEST_EQUAL( psa_close_key( 0 ), PSA_SUCCESS ); + TEST_EQUAL( psa_destroy_key( 0 ), PSA_SUCCESS ); /* After all this, check that the original handle is intact. */ PSA_ASSERT( psa_get_key_attributes( handle1, &attributes ) );