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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -113,3 +113,5 @@ typedef enum Tpm2Support {
|
||||
} Tpm2Support;
|
||||
|
||||
Tpm2Support tpm2_support(void);
|
||||
|
||||
int tpm2_parse_pcr_argument(const char *arg, uint32_t *mask);
|
||||
|
||||
Reference in New Issue
Block a user