3
3
#include "psa/crypto_se_driver.h"
4
4
5
5
#include "psa_crypto_se.h"
6
+ #include "psa_crypto_storage.h"
6
7
7
8
static struct
8
9
{
@@ -71,6 +72,23 @@ static struct
71
72
psa_status_t return_value;
72
73
} mock_destroy_data;
73
74
75
+ #define MAX_KEY_ID_FOR_TEST 10
76
+ static void psa_purge_storage( void )
77
+ {
78
+ psa_key_id_t id;
79
+ psa_key_lifetime_t lifetime;
80
+ /* The tests may have potentially created key ids from 1 to
81
+ * MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
82
+ * 0, which file-based storage uses as a temporary file. */
83
+ for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
84
+ psa_destroy_persistent_key( id );
85
+ /* Purge the transaction file. */
86
+ psa_crypto_stop_transaction( );
87
+ /* Purge driver persistent data. */
88
+ for( lifetime = 0; lifetime < PSA_MAX_SE_LIFETIME; lifetime++ )
89
+ psa_destroy_se_persistent_data( lifetime );
90
+ }
91
+
74
92
static void mock_teardown( void )
75
93
{
76
94
memset( &mock_import_data, 0, sizeof( mock_import_data ) );
@@ -81,6 +99,7 @@ static void mock_teardown( void )
81
99
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
82
100
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
83
101
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
102
+ psa_purge_storage( );
84
103
}
85
104
86
105
static psa_status_t mock_generate( psa_drv_se_context_t *drv_context,
0 commit comments