On Fri, Dec 04, 2020 at 10:43:34AM -0600, Glenn Washburn wrote: > This allows code using these structs to know the named key associated with > these json data structures. In the future we can use these to provide better > error messages to the user. > > Get rid of idx variable in luks2_get_keyslot() which was overloaded to be > used for both keyslot and segment slot keys. > > Signed-off-by: Glenn Washburn Personally, I'd have named them `json_slot_idx`. But you've already done so much work on improving the code that I don't want this to be the reason to not give an SOB, especially considering that it's a strict improvement anyway. So: Signed-off-by: Patrick Steinhardt > --- > grub-core/disk/luks2.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c > index eadd529e9..437c1da07 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -65,6 +65,8 @@ typedef struct grub_luks2_header grub_luks2_header_t; > > struct grub_luks2_keyslot > { > + /* The integer key to the associative array of keyslots */ > + grub_uint64_t json_slot_key; > grub_int64_t key_size; > grub_int64_t priority; > struct > @@ -103,6 +105,7 @@ typedef struct grub_luks2_keyslot grub_luks2_keyslot_t; > > struct grub_luks2_segment > { > + grub_uint64_t json_slot_key; > grub_uint64_t offset; > const char *size; > const char *encryption; > @@ -112,6 +115,7 @@ typedef struct grub_luks2_segment grub_luks2_segment_t; > > struct grub_luks2_digest > { > + grub_uint64_t json_slot_key; > /* Both keyslots and segments are interpreted as bitfields here */ > grub_uint64_t keyslots; > grub_uint64_t segments; > @@ -261,12 +265,11 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s > { > grub_json_t keyslots, keyslot, digests, digest, segments, segment; > grub_size_t i, size; > - grub_uint64_t idx; > > /* Get nth keyslot */ > if (grub_json_getvalue (&keyslots, root, "keyslots") || > grub_json_getchild (&keyslot, &keyslots, keyslot_idx) || > - grub_json_getuint64 (&idx, &keyslot, NULL) || > + grub_json_getuint64 (&k->json_slot_key, &keyslot, NULL) || > grub_json_getchild (&keyslot, &keyslot, 0) || > luks2_parse_keyslot (k, &keyslot)) > return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse keyslot %"PRIuGRUB_SIZE, keyslot_idx); > @@ -278,11 +281,12 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s > for (i = 0; i < size; i++) > { > if (grub_json_getchild (&digest, &digests, i) || > + grub_json_getuint64 (&d->json_slot_key, &digest, NULL) || > grub_json_getchild (&digest, &digest, 0) || > luks2_parse_digest (d, &digest)) > return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest %"PRIuGRUB_SIZE, i); > > - if ((d->keyslots & (1 << idx))) > + if ((d->keyslots & (1 << k->json_slot_key))) > break; > } > if (i == size) > @@ -295,12 +299,12 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s > for (i = 0; i < size; i++) > { > if (grub_json_getchild (&segment, &segments, i) || > - grub_json_getuint64 (&idx, &segment, NULL) || > + grub_json_getuint64 (&s->json_slot_key, &segment, NULL) || > grub_json_getchild (&segment, &segment, 0) || > luks2_parse_segment (s, &segment)) > return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse segment %"PRIuGRUB_SIZE, i); > > - if ((d->segments & (1 << idx))) > + if ((d->segments & (1 << s->json_slot_key))) > break; > } > if (i == size) > -- > 2.27.0 >