Skip to content

Commit 2bffacd

Browse files
committed
[nrf fromlist] 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 16c07e0e8cd697e31599f1114820428f2b095f8d) Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent f86c321 commit 2bffacd

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
@@ -25,6 +25,16 @@ static void fill_key_attributes(psa_key_attributes_t *key_attributes)
2525
psa_set_key_bits(key_attributes, KEY_BITS);
2626
}
2727

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

7787
ret = psa_get_key_attributes(ID, &retrieved_key_attributes);
7888
zassert_equal(ret, PSA_SUCCESS);
79-
zassert_mem_equal(&retrieved_key_attributes, &key_attributes, sizeof(key_attributes));
89+
compare_key_attributes(&retrieved_key_attributes, &key_attributes);
8090
ret = psa_destroy_key(ID);
8191
zassert_equal(ret, PSA_SUCCESS);
8292
ret = psa_get_key_attributes(ID, &retrieved_key_attributes);

0 commit comments

Comments
 (0)