summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-08-19 22:18:31 +0200
committerLennart Poettering <lennart@poettering.net>2022-09-08 16:34:27 +0200
commit4d5cc0d45322e71cf02cbef3022ff745e4bb3433 (patch)
treef9ea547f4957ec9e4b229ff88158192bd660ded6 /src
parenttpm2-util: add common parser for the LUKS2 TPM2 JSON structure (diff)
downloadsystemd-4d5cc0d45322e71cf02cbef3022ff745e4bb3433.tar.xz
systemd-4d5cc0d45322e71cf02cbef3022ff745e4bb3433.zip
tpm2-util: add helper for formatting PCR masks as string
Diffstat (limited to '')
-rw-r--r--src/shared/tpm2-util.c19
-rw-r--r--src/shared/tpm2-util.h2
2 files changed, 21 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;
+}
diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h
index 2ff7c0eb63..554ca58df6 100644
--- a/src/shared/tpm2-util.h
+++ b/src/shared/tpm2-util.h
@@ -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);