diff options
author | Dan Streetman <ddstreet@ieee.org> | 2023-01-24 10:19:03 -0500 |
---|---|---|
committer | Dan Streetman <ddstreet@ieee.org> | 2023-02-01 12:52:08 -0500 |
commit | 16e16b8c7b1621f3db96bfc357e5bba727c9dded (patch) | |
tree | 4cc4f101caca8b9c2809197b74ba39dd9f605ed1 /src/shared/tpm2-util.h | |
parent | 23e9ccc24ae0e7d3f3f609c69dbde171f1c55302 (diff) | |
download | systemd-16e16b8c7b1621f3db96bfc357e5bba727c9dded.tar.gz |
tpm2: add Tpm2Handle with automatic cleanup
This allows using _cleanup_ with the handles, which then allows removing the
use of goto in all functions that use the handles.
Diffstat (limited to 'src/shared/tpm2-util.h')
-rw-r--r-- | src/shared/tpm2-util.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index 9dc55d4a19..d26a945a90 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -67,7 +67,18 @@ Tpm2Context *tpm2_context_unref(Tpm2Context *context); DEFINE_TRIVIAL_CLEANUP_FUNC(Tpm2Context*, tpm2_context_unref); #define _cleanup_tpm2_context_ _cleanup_(tpm2_context_unrefp) -ESYS_TR tpm2_flush_context_verbose(Tpm2Context *c, ESYS_TR handle); +typedef struct { + Tpm2Context *tpm2_context; + ESYS_TR esys_handle; +} Tpm2Handle; + +#define _tpm2_handle(c, h) { .tpm2_context = (c), .esys_handle = (h), } +static const Tpm2Handle TPM2_HANDLE_NONE = _tpm2_handle(NULL, ESYS_TR_NONE); + +int tpm2_handle_new(Tpm2Context *context, Tpm2Handle **ret_handle); +Tpm2Handle *tpm2_handle_free(Tpm2Handle *handle); +DEFINE_TRIVIAL_CLEANUP_FUNC(Tpm2Handle*, tpm2_handle_free); +#define _cleanup_tpm2_handle_ _cleanup_(tpm2_handle_freep) void tpm2_pcr_mask_to_selection(uint32_t mask, uint16_t bank, TPML_PCR_SELECTION *ret); @@ -83,6 +94,7 @@ int tpm2_extend_bytes(Tpm2Context *c, char **banks, unsigned pcr_index, const vo #else /* HAVE_TPM2 */ typedef struct {} Tpm2Context; +typedef struct {} Tpm2Handle; #endif /* HAVE_TPM2 */ int tpm2_list_devices(void); |