Add tests for mbedtls_pk_can_do_ext() in test_suite_pktest_suite_pk

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function
index 32c2644..057a2e6 100644
--- a/tests/suites/test_suite_pk.function
+++ b/tests/suites/test_suite_pk.function
@@ -244,6 +244,47 @@
 }
 /* END_CASE */
 
+/* BEGIN_CASE depends_on:MBEDTLS_USE_PSA_CRYPTO */
+void pk_can_do_ext( int key_type, int key_usage, int key_alg, int key_alg2,
+                    int key_bits, int alg_check, int result )
+{
+    mbedtls_pk_context pk;
+    mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+    psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+
+    PSA_ASSERT( psa_crypto_init( ) );
+
+    mbedtls_pk_init( &pk );
+
+    psa_set_key_usage_flags( &attributes, key_usage );
+    psa_set_key_algorithm( &attributes, key_alg );
+    if( key_alg2 != 0 )
+        psa_set_key_enrollment_algorithm( &attributes, key_alg2 );
+    psa_set_key_type( &attributes, key_type );
+    psa_set_key_bits( &attributes, key_bits );
+
+    PSA_ASSERT( psa_generate_key( &attributes, &key ) );
+
+    if( mbedtls_svc_key_id_is_null( key ) )
+        goto exit;
+
+    TEST_EQUAL( mbedtls_pk_setup_opaque( &pk, key ), 0 );
+
+    TEST_EQUAL( mbedtls_pk_get_type( &pk ), MBEDTLS_PK_OPAQUE );
+
+    TEST_EQUAL( mbedtls_pk_can_do_ext( &pk, alg_check ), result );
+
+exit:
+    /*
+     * Key attributes may have been returned by psa_get_key_attributes()
+     * thus reset them as required.
+     */
+    psa_reset_key_attributes( &attributes );
+    PSA_ASSERT( psa_destroy_key( key ) );
+    mbedtls_pk_free( &pk ); /* redundant except upon error */
+    USE_PSA_DONE( );
+}
+/* END_CASE */
 
 /* BEGIN_CASE */
 void valid_parameters( )