Skip to content

Commit 200930d

Browse files
author
itayzafrir
committed
Refactor test partition helper function to create and generate a key
1 parent 2c1f0b3 commit 200930d

File tree

1 file changed

+20
-10
lines changed
  • TESTS/psa/crypto_access_control/COMPONENT_NSPE

1 file changed

+20
-10
lines changed

TESTS/psa/crypto_access_control/COMPONENT_NSPE/main.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ void inject_entropy()
5151
}
5252
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
5353

54+
static psa_status_t create_and_generate_key_via_test_partition(psa_key_id_t key_id, psa_key_type_t key_type,
55+
psa_algorithm_t key_alg, psa_key_usage_t key_usage,
56+
size_t key_bits, psa_key_handle_t *key_handle,
57+
unsigned char close_key)
58+
{
59+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, key_handle));
60+
TEST_ASSERT_NOT_EQUAL(0, *key_handle);
61+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(*key_handle, key_usage, key_alg));
62+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_generate_key(*key_handle, key_type, key_bits));
63+
if (close_key) {
64+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(*key_handle));
65+
}
66+
return (PSA_SUCCESS);
67+
}
68+
5469
void test_open_other_partition_key(void)
5570
{
5671
static const psa_key_id_t key_id = 999;
@@ -61,11 +76,8 @@ void test_open_other_partition_key(void)
6176
psa_key_handle_t key_handle = 0;
6277

6378
/* via test partition - create a key, set key policy, generate key material and close */
64-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
65-
TEST_ASSERT_NOT_EQUAL(0, key_handle);
66-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
67-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_generate_key(key_handle, key_type, key_bits));
68-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
79+
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
80+
key_bits, &key_handle, 1));
6981

7082
/* via test partition - reopen the key created by the test partition */
7183
key_handle = 0;
@@ -99,11 +111,9 @@ void test_create_key_same_id_different_partitions(void)
99111
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
100112

101113
/* via test partition - create a key, set key policy, generate key material and close */
102-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle_remote));
103-
TEST_ASSERT_NOT_EQUAL(0, key_handle_remote);
104-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle_remote, key_usage_remote, key_alg));
105-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_generate_key(key_handle_remote, key_type, key_bits_remote));
106-
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle_remote));
114+
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg,
115+
key_usage_remote, key_bits_remote,
116+
&key_handle_remote, 1));
107117

108118
/* create a key, set key policy, generate key material and close from current partition (i.e. NSPE) */
109119
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_create_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle_local));

0 commit comments

Comments
 (0)