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
{
@@ -76,6 +77,23 @@ static struct
76
77
psa_status_t return_value;
77
78
} mock_destroy_data;
78
79
80
+ #define MAX_KEY_ID_FOR_TEST 10
81
+ static void psa_purge_storage( void )
82
+ {
83
+ psa_key_id_t id;
84
+ psa_key_lifetime_t lifetime;
85
+ /* The tests may have potentially created key ids from 1 to
86
+ * MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
87
+ * 0, which file-based storage uses as a temporary file. */
88
+ for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
89
+ psa_destroy_persistent_key( id );
90
+ /* Purge the transaction file. */
91
+ psa_crypto_stop_transaction( );
92
+ /* Purge driver persistent data. */
93
+ for( lifetime = 0; lifetime < PSA_MAX_SE_LIFETIME; lifetime++ )
94
+ psa_destroy_se_persistent_data( lifetime );
95
+ }
96
+
79
97
static void mock_teardown( void )
80
98
{
81
99
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
@@ -86,6 +104,7 @@ static void mock_teardown( void )
86
104
memset( &mock_verify_data, 0, sizeof( mock_verify_data ) );
87
105
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
88
106
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
107
+ psa_purge_storage( );
89
108
}
90
109
91
110
static psa_status_t mock_generate( psa_drv_se_context_t *context,
0 commit comments