1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Refactor the key-components mechanism a bit.

Having recently pulled it out into its own file, I think it could also
do with a bit of tidying. In this rework:

 - the substructure for a single component now has a globally visible
   struct tag, so you can make a variable pointing at it, saving
   verbiage in every piece of code looping over a key_components

 - the 'is_mp_int' flag has been replaced with a type enum, so that
   more types can be added without further upheaval

 - the printing loop in cmdgen.c for puttygen --dump has factored out
   the initial 'name=' prefix on each line so that it isn't repeated
   per component type

 - the storage format for text components is now a strbuf rather than
   a plain char *, which I think is generally more useful.
This commit is contained in:
Simon Tatham
2022-04-18 10:10:57 +01:00
parent cf36b9215f
commit 68514ac8a1
5 changed files with 48 additions and 30 deletions

View File

@ -309,7 +309,7 @@ FUNC(uint, ssh_key_public_bits, ARG(keyalg, self), ARG(val_string_ptrlen, blob))
FUNC(uint, key_components_count, ARG(val_keycomponents, kc))
FUNC(opt_val_string_asciz_const, key_components_nth_name,
ARG(val_keycomponents, kc), ARG(uint, n))
FUNC(opt_val_string_asciz_const, key_components_nth_str,
FUNC(opt_val_string, key_components_nth_str,
ARG(val_keycomponents, kc), ARG(uint, n))
FUNC(opt_val_mpint, key_components_nth_mp, ARG(val_keycomponents, kc),
ARG(uint, n))

View File

@ -1227,16 +1227,18 @@ const char *key_components_nth_name(key_components *kc, size_t n)
return (n >= kc->ncomponents ? NULL :
kc->components[n].name);
}
const char *key_components_nth_str(key_components *kc, size_t n)
strbuf *key_components_nth_str(key_components *kc, size_t n)
{
return (n >= kc->ncomponents ? NULL :
kc->components[n].is_mp_int ? NULL :
kc->components[n].text);
if (n >= kc->ncomponents)
return NULL;
if (kc->components[n].type != KCT_TEXT)
return NULL;
return strbuf_dup(ptrlen_from_strbuf(kc->components[n].str));
}
mp_int *key_components_nth_mp(key_components *kc, size_t n)
{
return (n >= kc->ncomponents ? NULL :
!kc->components[n].is_mp_int ? NULL :
kc->components[n].type != KCT_MPINT ? NULL :
mp_copy(kc->components[n].mp));
}