1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Move key_components management functions into utils.

They're pretty much self-contained, and don't really need to be in the
same module as sshpubk.c (which has other dependencies). Move them out
into a utils module, where pulling them in won't pull in anything else
unwanted.
This commit is contained in:
Simon Tatham 2022-04-15 15:20:16 +01:00
parent c0fba758e6
commit 1500da80f1
3 changed files with 47 additions and 44 deletions

View File

@ -1936,47 +1936,3 @@ const char *key_type_to_str(int type)
unreachable("bad key type in key_type_to_str");
}
}
key_components *key_components_new(void)
{
key_components *kc = snew(key_components);
kc->ncomponents = 0;
kc->componentsize = 0;
kc->components = NULL;
return kc;
}
void key_components_add_text(key_components *kc,
const char *name, const char *value)
{
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
size_t n = kc->ncomponents++;
kc->components[n].name = dupstr(name);
kc->components[n].is_mp_int = false;
kc->components[n].text = dupstr(value);
}
void key_components_add_mp(key_components *kc,
const char *name, mp_int *value)
{
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
size_t n = kc->ncomponents++;
kc->components[n].name = dupstr(name);
kc->components[n].is_mp_int = true;
kc->components[n].mp = mp_copy(value);
}
void key_components_free(key_components *kc)
{
for (size_t i = 0; i < kc->ncomponents; i++) {
sfree(kc->components[i].name);
if (kc->components[i].is_mp_int) {
mp_free(kc->components[i].mp);
} else {
smemclr(kc->components[i].text, strlen(kc->components[i].text));
sfree(kc->components[i].text);
}
}
sfree(kc->components);
sfree(kc);
}

View File

@ -28,6 +28,7 @@ add_sources_from_current_dir(utils
host_strcspn.c
host_strduptrim.c
host_strrchr.c
key_components.c
log_proxy_stderr.c
make_spr_sw_abort_static.c
marshal.c

46
utils/key_components.c Normal file
View File

@ -0,0 +1,46 @@
#include "ssh.h"
#include "mpint.h"
key_components *key_components_new(void)
{
key_components *kc = snew(key_components);
kc->ncomponents = 0;
kc->componentsize = 0;
kc->components = NULL;
return kc;
}
void key_components_add_text(key_components *kc,
const char *name, const char *value)
{
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
size_t n = kc->ncomponents++;
kc->components[n].name = dupstr(name);
kc->components[n].is_mp_int = false;
kc->components[n].text = dupstr(value);
}
void key_components_add_mp(key_components *kc,
const char *name, mp_int *value)
{
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
size_t n = kc->ncomponents++;
kc->components[n].name = dupstr(name);
kc->components[n].is_mp_int = true;
kc->components[n].mp = mp_copy(value);
}
void key_components_free(key_components *kc)
{
for (size_t i = 0; i < kc->ncomponents; i++) {
sfree(kc->components[i].name);
if (kc->components[i].is_mp_int) {
mp_free(kc->components[i].mp);
} else {
smemclr(kc->components[i].text, strlen(kc->components[i].text));
sfree(kc->components[i].text);
}
}
sfree(kc->components);
sfree(kc);
}