From 04129a0d960d5b7831fcfb1f71574ff3ffc6fe5e Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 9 Oct 2019 16:23:49 +0200 Subject: [PATCH] Update slot management tests now that {close,destroy}_key(0) succeed --- ..._suite_psa_crypto_slot_management.function | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 3b9eada83c..c269280bf0 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 ) );