Skip to content

Commit 7ea8719

Browse files
tomi-fontnordicjm
authored andcommitted
[nrf fromtree] tests: secure_storage: psa: crypto: improve compatibility
The psa_key_attributes_t type is implementation-defined according to the PSA Crypto spec. Compare its fields individually instead of doing a memcmp() over the entire struct. Signed-off-by: Tomi Fontanilles <[email protected]> (cherry picked from commit 744e9f7) Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent a25514b commit 7ea8719

File tree

1 file changed

+11
-1
lines changed
  • tests/subsys/secure_storage/psa/crypto/src

1 file changed

+11
-1
lines changed

tests/subsys/secure_storage/psa/crypto/src/main.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ static void fill_key_attributes(psa_key_attributes_t *key_attributes)
2626
psa_set_key_bits(key_attributes, KEY_BITS);
2727
}
2828

29+
static void compare_key_attributes(const psa_key_attributes_t *l, const psa_key_attributes_t *r)
30+
{
31+
zassert_equal(psa_get_key_lifetime(l), psa_get_key_lifetime(r));
32+
zassert_equal(psa_get_key_usage_flags(l), psa_get_key_usage_flags(r));
33+
zassert_equal(psa_get_key_id(l), psa_get_key_id(r));
34+
zassert_equal(psa_get_key_type(l), psa_get_key_type(r));
35+
zassert_equal(psa_get_key_algorithm(l), psa_get_key_algorithm(r));
36+
zassert_equal(psa_get_key_bits(l), psa_get_key_bits(r));
37+
}
38+
2939
static void fill_data(uint8_t *data, size_t size)
3040
{
3141
zassert_equal(psa_generate_random(data, size), PSA_SUCCESS);
@@ -77,7 +87,7 @@ ZTEST(secure_storage_psa_crypto, test_its_caller_isolation)
7787

7888
ret = psa_get_key_attributes(ID, &retrieved_key_attributes);
7989
zassert_equal(ret, PSA_SUCCESS);
80-
zassert_mem_equal(&retrieved_key_attributes, &key_attributes, sizeof(key_attributes));
90+
compare_key_attributes(&retrieved_key_attributes, &key_attributes);
8191
ret = psa_destroy_key(ID);
8292
zassert_equal(ret, PSA_SUCCESS);
8393
ret = psa_get_key_attributes(ID, &retrieved_key_attributes);

0 commit comments

Comments
 (0)