]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm2-util: add helper for formatting PCR masks as string
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Aug 2022 20:18:31 +0000 (22:18 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Sep 2022 14:34:27 +0000 (16:34 +0200)
src/shared/tpm2-util.c
src/shared/tpm2-util.h

index f5b97fae73a70ab76e1bf85cfcdb4db72e11bca5..7c9eb77f95dae0c8f03989c85306a66085ad90c4 100644 (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;
+}
index 2ff7c0eb63b01a0a15104326360693f23d872cda..554ca58df6a76eaeb6afea0fbb3db1d9afad57b0 100644 (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);