From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 2/6] crypto/tlscredsx509: Access QOM parent via QCRYPTO_TLS_CREDS() macro
Date: Mon, 10 Feb 2025 17:21:31 +0100 [thread overview]
Message-ID: <20250210162135.14123-3-philmd@linaro.org> (raw)
In-Reply-To: <20250210162135.14123-1-philmd@linaro.org>
Prefer accessing QCryptoTLSCredsX509's QOM parent via the
QCRYPTO_TLS_CREDS() cast macro, rather than parent_obj.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
crypto/tlscredsx509.c | 45 +++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c
index eb197e145f3..84b88747f21 100644
--- a/crypto/tlscredsx509.c
+++ b/crypto/tlscredsx509.c
@@ -534,40 +534,41 @@ static int
qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *x509_creds,
Error **errp)
{
+ QCryptoTLSCreds *creds = QCRYPTO_TLS_CREDS(x509_creds);
char *cacert = NULL, *cacrl = NULL, *cert = NULL,
*key = NULL, *dhparams = NULL;
int ret;
int rv = -1;
trace_qcrypto_tls_creds_x509_load(x509_creds,
- x509_creds->parent_obj.dir ? x509_creds->parent_obj.dir : "<nodir>");
+ creds->dir ? creds->dir : "<nodir>");
- if (x509_creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
- if (qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+ if (qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_CA_CERT,
true, &cacert, errp) < 0 ||
- qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_CA_CRL,
false, &cacrl, errp) < 0 ||
- qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_SERVER_CERT,
true, &cert, errp) < 0 ||
- qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_SERVER_KEY,
true, &key, errp) < 0 ||
- qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_DH_PARAMS,
false, &dhparams, errp) < 0) {
goto cleanup;
}
} else {
- if (qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ if (qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_CA_CERT,
true, &cacert, errp) < 0 ||
- qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_CLIENT_CERT,
false, &cert, errp) < 0 ||
- qcrypto_tls_creds_get_path(&x509_creds->parent_obj,
+ qcrypto_tls_creds_get_path(creds,
QCRYPTO_TLS_CREDS_X509_CLIENT_KEY,
false, &key, errp) < 0) {
goto cleanup;
@@ -576,7 +577,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *x509_creds,
if (x509_creds->sanityCheck &&
qcrypto_tls_creds_x509_sanity_check(x509_creds,
- x509_creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER,
+ creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER,
cacert, cert, errp) < 0) {
goto cleanup;
}
@@ -630,14 +631,14 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *x509_creds,
}
}
- if (x509_creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
- if (qcrypto_tls_creds_get_dh_params_file(&x509_creds->parent_obj, dhparams,
- &x509_creds->parent_obj.dh_params,
+ if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+ if (qcrypto_tls_creds_get_dh_params_file(creds, dhparams,
+ &creds->dh_params,
errp) < 0) {
goto cleanup;
}
gnutls_certificate_set_dh_params(x509_creds->data,
- x509_creds->parent_obj.dh_params);
+ creds->dh_params);
}
rv = 0;
@@ -654,13 +655,15 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *x509_creds,
static void
qcrypto_tls_creds_x509_unload(QCryptoTLSCredsX509 *x509_creds)
{
+ QCryptoTLSCreds *creds = QCRYPTO_TLS_CREDS(x509_creds);
+
if (x509_creds->data) {
gnutls_certificate_free_credentials(x509_creds->data);
x509_creds->data = NULL;
}
- if (x509_creds->parent_obj.dh_params) {
- gnutls_dh_params_deinit(x509_creds->parent_obj.dh_params);
- x509_creds->parent_obj.dh_params = NULL;
+ if (creds->dh_params) {
+ gnutls_dh_params_deinit(creds->dh_params);
+ creds->dh_params = NULL;
}
}
@@ -746,15 +749,15 @@ qcrypto_tls_creds_x509_reload(QCryptoTLSCreds *creds, Error **errp)
QCryptoTLSCredsX509 *x509_creds = QCRYPTO_TLS_CREDS_X509(creds);
Error *local_err = NULL;
gnutls_certificate_credentials_t creds_data = x509_creds->data;
- gnutls_dh_params_t creds_dh_params = x509_creds->parent_obj.dh_params;
+ gnutls_dh_params_t creds_dh_params = creds->dh_params;
x509_creds->data = NULL;
- x509_creds->parent_obj.dh_params = NULL;
+ creds->dh_params = NULL;
qcrypto_tls_creds_x509_load(x509_creds, &local_err);
if (local_err) {
qcrypto_tls_creds_x509_unload(x509_creds);
x509_creds->data = creds_data;
- x509_creds->parent_obj.dh_params = creds_dh_params;
+ creds->dh_params = creds_dh_params;
error_propagate(errp, local_err);
return false;
}
--
2.47.1
next prev parent reply other threads:[~2025-02-10 16:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 16:21 [PATCH 0/6] crypto/tlscreds: QOM style cleanups Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 1/6] crypto/tlscredsx509: Rename 'creds' -> 'x509_creds' Philippe Mathieu-Daudé
2025-02-10 16:32 ` Daniel P. Berrangé
2025-02-10 16:21 ` Philippe Mathieu-Daudé [this message]
2025-02-10 16:21 ` [PATCH 3/6] crypto/tlscredspsk: Rename 'creds' -> 'psk_creds' Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 4/6] crypto/tlscredspsk: Access QOM parent via QCRYPTO_TLS_CREDS() macro Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 5/6] crypto/tlscredsanon: Rename 'creds' -> 'anon_creds' Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 6/6] crypto/tlscredsanon: Access QOM parent via QCRYPTO_TLS_CREDS() macro Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250210162135.14123-3-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).