Skip to content

Commit

Permalink
crypto/tlscreds: Introduce qcrypto_tls_creds_check_endpoint() helper
Browse files Browse the repository at this point in the history
Introduce the qcrypto_tls_creds_check_endpoint() helper
to access QCryptoTLSCreds internal 'endpoint' field.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
  • Loading branch information
philmd authored and berrange committed Jun 29, 2021
1 parent 13d5f87 commit e9ac680
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crypto/tlscreds.c
Expand Up @@ -20,6 +20,7 @@

#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi-types-crypto.h"
#include "qemu/module.h"
#include "tlscredspriv.h"
#include "trace.h"
Expand Down Expand Up @@ -259,6 +260,17 @@ qcrypto_tls_creds_finalize(Object *obj)
g_free(creds->priority);
}

bool qcrypto_tls_creds_check_endpoint(QCryptoTLSCreds *creds,
QCryptoTLSCredsEndpoint endpoint,
Error **errp)
{
if (creds->endpoint != endpoint) {
error_setg(errp, "Expected TLS credentials for a %s endpoint",
QCryptoTLSCredsEndpoint_str(endpoint));
return false;
}
return true;
}

static const TypeInfo qcrypto_tls_creds_info = {
.parent = TYPE_OBJECT,
Expand Down
14 changes: 14 additions & 0 deletions include/crypto/tlscreds.h
Expand Up @@ -65,5 +65,19 @@ struct QCryptoTLSCredsClass {
CryptoTLSCredsReload reload;
};

/**
* qcrypto_tls_creds_check_endpoint:
* @creds: pointer to a TLS credentials object
* @endpoint: type of network endpoint that will be using the credentials
* @errp: pointer to a NULL-initialized error object
*
* Check whether the credentials is setup according to
* the type of @endpoint argument.
*
* Returns true if the credentials is setup for the endpoint, false otherwise
*/
bool qcrypto_tls_creds_check_endpoint(QCryptoTLSCreds *creds,
QCryptoTLSCredsEndpoint endpoint,
Error **errp);

#endif /* QCRYPTO_TLSCREDS_H */

0 comments on commit e9ac680

Please sign in to comment.