mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
tpm2-util: add helper for formatting PCR masks as string
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user