Replace mbedtls_pk_get_name with pk_key_type_to_string

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
This commit is contained in:
Ben Taylor
2025-12-09 08:11:28 +00:00
parent f7173e4389
commit 2481daa309
6 changed files with 32 additions and 5 deletions

View File

@@ -315,6 +315,16 @@ mbedtls_x509_san_list;
*/
int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn);
/**
* \brief Convert the pk_key_type to a string.
*
* \param[in] pk A mbedtls_pk_context struct containing the pk_key_type to
convert
* \return A pointer to a string containing the pk_key_type.
*/
const char *pk_key_type_to_string(const mbedtls_pk_context *pk);
/**
* \brief Convert the certificate DN string \p name into
* a linked list of mbedtls_x509_name (equivalent to

View File

@@ -122,6 +122,23 @@ int mbedtls_x509_get_alg(unsigned char **p, const unsigned char *end,
return 0;
}
/*
* Convert pk_key_type to a string
*/
const char *pk_key_type_to_string(const mbedtls_pk_context *pk)
{
psa_key_type_t key_type;
key_type = mbedtls_pk_get_key_type(pk);
if(PSA_KEY_TYPE_IS_RSA(key_type)){
return "RSA";
} else if(PSA_KEY_TYPE_IS_ECC(key_type)){
return "EC";
} else {
return "NONE";
}
}
/*
* Convert md type to string
*/

View File

@@ -1806,7 +1806,7 @@ int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
/* Key size */
if ((ret = mbedtls_x509_key_size_helper(key_size_str, MBEDTLS_BEFORE_COLON,
mbedtls_pk_get_name(&crt->pk))) != 0) {
pk_key_type_to_string(&crt->pk))) != 0) {
return ret;
}

View File

@@ -551,7 +551,7 @@ int mbedtls_x509_csr_info(char *buf, size_t size, const char *prefix,
MBEDTLS_X509_SAFE_SNPRINTF;
if ((ret = mbedtls_x509_key_size_helper(key_size_str, MBEDTLS_BEFORE_COLON,
mbedtls_pk_get_name(&csr->pk))) != 0) {
pk_key_type_to_string(&csr->pk))) != 0) {
return ret;
}

View File

@@ -1770,7 +1770,7 @@ usage:
mbedtls_printf(" ok (key type: %s)\n",
strlen(opt.key_file) || strlen(opt.key_opaque_alg1) ?
mbedtls_pk_get_name(&pkey) : "none");
pk_key_type_to_string(&pkey) : "none");
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
/*

View File

@@ -2723,8 +2723,8 @@ usage:
}
mbedtls_printf(" ok (key types: %s, %s)\n",
key_cert_init ? mbedtls_pk_get_name(&pkey) : "none",
key_cert_init2 ? mbedtls_pk_get_name(&pkey2) : "none");
key_cert_init ? pk_key_type_to_string(&pkey) : "none",
key_cert_init2 ? pk_key_type_to_string(&pkey2) : "none");
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
#if defined(SNI_OPTION)