From 3da24c19ade5584bd05a3482de814fccc05602fc Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 27 Jan 2021 15:37:34 -0600 Subject: [PATCH] asn1: Template backend partial support for SETs This adds enough support for SET { ... } types to the template backend to allow the X.690 sample test to be run with the template backend. Limitations: - For DER encoding, the SET { ... } members must be manually sorted by the module author. - Decoding of out-of-order encodings (BER) is not supported at this time. These shortcomings will be addressed later. Note that because we don't parse IMPORTed modules at this time, we can't sort SET { ... } members at compile time if any of them out an outer-most tag that the compiler cannot see without learning to parse IMPORTed modules. --- lib/asn1/gen_template.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/asn1/gen_template.c b/lib/asn1/gen_template.c index 1ddb07038..2879a16b6 100644 --- a/lib/asn1/gen_template.c +++ b/lib/asn1/gen_template.c @@ -631,6 +631,32 @@ template_members(struct templatehead *temp, const char *basetype, const char *na break; } + case TSet: { + Member *m; + + fprintf(get_code_file(), "/* tset: members isstruct: %d */\n", isstruct); + + HEIM_TAILQ_FOREACH(m, t->members, members) { + char *newbasename = NULL; + + if (m->ellipsis) + continue; + + if (name) { + if (asprintf(&newbasename, "%s_%s", basetype, name) < 0) + errx(1, "malloc"); + } else + newbasename = strdup(basetype); + if (newbasename == NULL) + errx(1, "malloc"); + + template_members(temp, newbasename, m->gen_name, m->type, m->optional, 0, isstruct, 1); + + free(newbasename); + } + + break; + } case TSequence: { Member *m;