mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Extra helper functions for adding key_components.
In this commit, I provide further functions which generate the existing set of data types: - key_components_add_text_pl() adds a text component, but takes a ptrlen rather than a const char *, in case that was what you happened to have already. - key_components_add_uint() ends up adding an mp_int to the structure, but takes it as input in the form of an ordinary C integer, for the convenience of call sites which will want to do that a lot and don't enjoy repeating the mp_int construction boilerplate - key_components_add_copy() takes a pointer to one of the key_component sub-structs in an existing key_components, and copies it into the output key_components under a new name, handling whatever type it turns out to have.
This commit is contained in:
parent
62bc6c5448
commit
180d1b78de
6
ssh.h
6
ssh.h
@ -560,10 +560,16 @@ typedef struct key_components {
|
|||||||
key_components *key_components_new(void);
|
key_components *key_components_new(void);
|
||||||
void key_components_add_text(key_components *kc,
|
void key_components_add_text(key_components *kc,
|
||||||
const char *name, const char *value);
|
const char *name, const char *value);
|
||||||
|
void key_components_add_text_pl(key_components *kc,
|
||||||
|
const char *name, ptrlen value);
|
||||||
void key_components_add_binary(key_components *kc,
|
void key_components_add_binary(key_components *kc,
|
||||||
const char *name, ptrlen value);
|
const char *name, ptrlen value);
|
||||||
void key_components_add_mp(key_components *kc,
|
void key_components_add_mp(key_components *kc,
|
||||||
const char *name, mp_int *value);
|
const char *name, mp_int *value);
|
||||||
|
void key_components_add_uint(key_components *kc,
|
||||||
|
const char *name, uintmax_t value);
|
||||||
|
void key_components_add_copy(key_components *kc,
|
||||||
|
const char *name, const key_component *value);
|
||||||
void key_components_free(key_components *kc);
|
void key_components_free(key_components *kc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -26,6 +26,12 @@ void key_components_add_text(key_components *kc,
|
|||||||
key_components_add_str(kc, name, KCT_TEXT, ptrlen_from_asciz(value));
|
key_components_add_str(kc, name, KCT_TEXT, ptrlen_from_asciz(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void key_components_add_text_pl(key_components *kc,
|
||||||
|
const char *name, ptrlen value)
|
||||||
|
{
|
||||||
|
key_components_add_str(kc, name, KCT_TEXT, value);
|
||||||
|
}
|
||||||
|
|
||||||
void key_components_add_binary(key_components *kc,
|
void key_components_add_binary(key_components *kc,
|
||||||
const char *name, ptrlen value)
|
const char *name, ptrlen value)
|
||||||
{
|
{
|
||||||
@ -42,6 +48,29 @@ void key_components_add_mp(key_components *kc,
|
|||||||
kc->components[n].mp = mp_copy(value);
|
kc->components[n].mp = mp_copy(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void key_components_add_uint(key_components *kc,
|
||||||
|
const char *name, uintmax_t value)
|
||||||
|
{
|
||||||
|
mp_int *mpvalue = mp_from_integer(value);
|
||||||
|
key_components_add_mp(kc, name, mpvalue);
|
||||||
|
mp_free(mpvalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void key_components_add_copy(key_components *kc,
|
||||||
|
const char *name, const key_component *value)
|
||||||
|
{
|
||||||
|
switch (value->type) {
|
||||||
|
case KCT_TEXT:
|
||||||
|
case KCT_BINARY:
|
||||||
|
key_components_add_str(kc, name, value->type,
|
||||||
|
ptrlen_from_strbuf(value->str));
|
||||||
|
break;
|
||||||
|
case KCT_MPINT:
|
||||||
|
key_components_add_mp(kc, name, value->mp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void key_components_free(key_components *kc)
|
void key_components_free(key_components *kc)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < kc->ncomponents; i++) {
|
for (size_t i = 0; i < kc->ncomponents; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user