diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-08-19 22:18:31 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-09-08 16:34:27 +0200 |
commit | 4d5cc0d45322e71cf02cbef3022ff745e4bb3433 (patch) | |
tree | f9ea547f4957ec9e4b229ff88158192bd660ded6 /src/shared/tpm2-util.c | |
parent | fdf6c27cbaea5af63b474b6160c1effa5f3a3b46 (diff) | |
download | systemd-4d5cc0d45322e71cf02cbef3022ff745e4bb3433.tar.gz |
tpm2-util: add helper for formatting PCR masks as string
Diffstat (limited to 'src/shared/tpm2-util.c')
-rw-r--r-- | src/shared/tpm2-util.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index f5b97fae73..7c9eb77f95 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -2160,3 +2160,22 @@ int tpm2_load_pcr_public_key(const char *path, void **ret_pubkey, size_t *ret_pu return 0; } + +int pcr_mask_to_string(uint32_t mask, char **ret) { + _cleanup_free_ char *buf = NULL; + int r; + + assert(ret); + + for (unsigned i = 0; i < TPM2_PCRS_MAX; i++) { + if (!(mask & (UINT32_C(1) << i))) + continue; + + r = strextendf_with_separator(&buf, "+", "%u", i); + if (r < 0) + return r; + } + + *ret = TAKE_PTR(buf); + return 0; +} |