Skip to content

Commit dd835cb

Browse files
Add a few tests for persistent attributes
psa_set_key_lifetime and psa_set_key_id aren't pure setters: they also set the other attribute in some conditions. Add dedicated tests for this behavior.
1 parent 9de5eb0 commit dd835cb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/suites/test_suite_psa_crypto.data

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ static_checks:
44
PSA key attributes structure
55
attributes_set_get:0x6963:PSA_KEY_LIFETIME_PERSISTENT:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CCM:PSA_KEY_TYPE_AES:128
66

7+
PSA key attributes: id only
8+
persistence_attributes:0x1234:-1:-1:0x1234:PSA_KEY_LIFETIME_PERSISTENT
9+
10+
PSA key attributes: lifetime=3 only
11+
persistence_attributes:-1:3:-1:0:3
12+
13+
PSA key attributes: id then back to volatile
14+
persistence_attributes:0x1234:PSA_KEY_LIFETIME_VOLATILE:-1:0:PSA_KEY_LIFETIME_VOLATILE
15+
16+
PSA key attributes: id then lifetime
17+
persistence_attributes:0x1234:3:-1:0x1234:3
18+
19+
PSA key attributes: lifetime then id
20+
persistence_attributes:0x1234:3:0x1235:0x1235:3
21+
722
PSA import/export raw: 0 bytes
823
import_export:"":PSA_KEY_TYPE_RAW_DATA:0:PSA_KEY_USAGE_EXPORT:0:0:PSA_SUCCESS:1
924

tests/suites/test_suite_psa_crypto.function

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,29 @@ void attributes_set_get( int id_arg, int lifetime_arg,
12041204
}
12051205
/* END_CASE */
12061206

1207+
/* BEGIN_CASE */
1208+
void persistence_attributes( int id1_arg, int lifetime_arg, int id2_arg,
1209+
int expected_id_arg, int expected_lifetime_arg )
1210+
{
1211+
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
1212+
psa_key_id_t id1 = id1_arg;
1213+
psa_key_lifetime_t lifetime = lifetime_arg;
1214+
psa_key_id_t id2 = id2_arg;
1215+
psa_key_id_t expected_id = expected_id_arg;
1216+
psa_key_lifetime_t expected_lifetime = expected_lifetime_arg;
1217+
1218+
if( id1_arg != -1 )
1219+
psa_set_key_id( &attributes, id1 );
1220+
if( lifetime_arg != -1 )
1221+
psa_set_key_lifetime( &attributes, lifetime );
1222+
if( id2_arg != -1 )
1223+
psa_set_key_id( &attributes, id2 );
1224+
1225+
TEST_EQUAL( psa_get_key_id( &attributes ), expected_id );
1226+
TEST_EQUAL( psa_get_key_lifetime( &attributes ), expected_lifetime );
1227+
}
1228+
/* END_CASE */
1229+
12071230
/* BEGIN_CASE */
12081231
void import( data_t *data, int type_arg,
12091232
int attr_bits_arg,

0 commit comments

Comments
 (0)