1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-12 08:43:53 -05:00

Factor KEXINIT analysis out into its own function.

The function takes the two KEXINIT packets in their string form,
together with a list of mappings from names to known algorithm
implementations, and returns the selected one of each kind, along with
all the other necessary auxiliary stuff.
This commit is contained in:
Simon Tatham
2018-10-07 13:51:04 +01:00
parent 3df80af868
commit 7de8801e73
3 changed files with 365 additions and 211 deletions

View File

@ -596,6 +596,38 @@ void add_to_commasep(strbuf *buf, const char *data)
put_data(buf, data, strlen(data));
}
int get_commasep_word(ptrlen *list, ptrlen *word)
{
const char *comma;
/*
* Discard empty list elements, should there be any, because we
* never want to return one as if it was a real string. (This
* introduces a mild tolerance of badly formatted data in lists we
* receive, but I think that's acceptable.)
*/
while (list->len > 0 && *(const char *)list->ptr == ',') {
list->ptr = (const char *)list->ptr + 1;
list->len--;
}
if (!list->len)
return FALSE;
comma = memchr(list->ptr, ',', list->len);
if (!comma) {
*word = *list;
list->len = 0;
} else {
size_t wordlen = comma - (const char *)list->ptr;
word->ptr = list->ptr;
word->len = wordlen;
list->ptr = (const char *)list->ptr + wordlen + 1;
list->len -= wordlen + 1;
}
return TRUE;
}
/* ----------------------------------------------------------------------
* Functions for translating SSH packet type codes into their symbolic
* string names.