tpm2-util: add helper for formatting PCR masks as string

This commit is contained in:
Lennart Poettering
2022-08-19 22:18:31 +02:00
parent fdf6c27cba
commit 4d5cc0d453
2 changed files with 21 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -146,3 +146,5 @@ int tpm2_parse_pcr_argument(const char *arg, uint32_t *mask);
int tpm2_load_pcr_signature(const char *path, JsonVariant **ret);
int tpm2_load_pcr_public_key(const char *path, void **ret_pubkey, size_t *ret_pubkey_size);
int pcr_mask_to_string(uint32_t mask, char **ret);