tpm2-util: introduce tpm2_parse_pcr_argument() helper

Add a new tpm2_parse_pcr_argument() helper that unifies how we merge PCR
masks in a single function, we can use all over the place. Previously we
had basically the same code for this at 4 places.
This commit is contained in:
Lennart Poettering
2022-08-19 21:26:26 +02:00
parent 466266c172
commit 222a951fa4
6 changed files with 36 additions and 59 deletions
+25
View File
@@ -1508,3 +1508,28 @@ Tpm2Support tpm2_support(void) {
return support;
}
int tpm2_parse_pcr_argument(const char *arg, uint32_t *mask) {
uint32_t m;
int r;
assert(mask);
/* For use in getopt_long() command line parsers: merges masks specified on the command line */
if (isempty(arg)) {
*mask = 0;
return 0;
}
r = tpm2_parse_pcrs(arg, &m);
if (r < 0)
return r;
if (*mask == UINT32_MAX)
*mask = m;
else
*mask |= m;
return 0;
}
+2
View File
@@ -113,3 +113,5 @@ typedef enum Tpm2Support {
} Tpm2Support;
Tpm2Support tpm2_support(void);
int tpm2_parse_pcr_argument(const char *arg, uint32_t *mask);