From 1500da80f182a993cf0a7da7e143ab9bb623e2d3 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 15 Apr 2022 15:20:16 +0100 Subject: [PATCH] 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. --- sshpubk.c | 44 ---------------------------------------- utils/CMakeLists.txt | 1 + utils/key_components.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 utils/key_components.c diff --git a/sshpubk.c b/sshpubk.c index 003213ca..326fe31c 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -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); -} diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 80fc20b8..787bcefc 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -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 diff --git a/utils/key_components.c b/utils/key_components.c new file mode 100644 index 00000000..bb9ff40d --- /dev/null +++ b/utils/key_components.c @@ -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); +}