From 45451814b383119d75db941241fba54309c562b0 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 16 Dec 2020 15:10:58 -0600 Subject: [PATCH] asn1: Add breadcrumbs for future work --- lib/asn1/gen_locl.h | 55 +++++++++++++++++++++++++++++++++++++++++ lib/asn1/gen_template.c | 3 +++ 2 files changed, 58 insertions(+) diff --git a/lib/asn1/gen_locl.h b/lib/asn1/gen_locl.h index 288631e98..61e728886 100644 --- a/lib/asn1/gen_locl.h +++ b/lib/asn1/gen_locl.h @@ -48,12 +48,67 @@ #include #include #include +#include #include "hash.h" #include "symbol.h" #include "asn1-common.h" #include "der.h" #include "der-private.h" +/* + * XXX We need to move all module state out of globals and into a struct that + * we pass around when parsing and compiling a module, and also that we keep on + * a linked list of parsed modules. + * + * This is needed to: + * + * - implement IMPORTS correctly, because we need to know the type of a symbol + * in order to emit an extern declaration of it + * - implement value parsing + * - implement an ASN.1 library that does value parsing + * + * Value parsing, in particular, would be fantastic. We could then have + * options in hxtool(1) to load arbitrary ASN.1 modules and then parse SAN + * values given in ASN.1 value syntax on the command-line or in files. Eat + * your heart out OpenSSL if we do this! + * + * As well we'll need a `-I' option to the compiler so it knows where to find + * modules to IMPORT FROM. + */ +typedef struct asn1_module { + /* Name of ASN.1 module file: */ + const char *orig_filename; + /* Name of file to always include for common type definitions: */ + const char *type_file_string; + /* Name of public header file for module: */ + const char *header; + /* Name of private header file for module: */ + const char *privheader; + /* Basename of module: */ + const char *headerbase; + /* Open stdio file handles for output: */ + FILE *privheaderfile; + FILE *headerfile; + FILE *oidsfile; + FILE *codefile; + FILE *logfile; + FILE *templatefile; + /* Module contents: */ + struct sexport *exports; + struct import *imports; + Hashtab *htab; /* symbols */ + /* Template state: */ + struct templatehead *template; + struct tlisthead *tlistmaster; + /* CLI options and flags needed everywhere: */ + getarg_strings preserve; + getarg_strings seq; + unsigned int one_code_file:1; + unsigned int support_ber:1; + unsigned int parse_units_flag:1; + unsigned int rfc1510_bitstring:1; /* Should be a getarg_strings of bitrsting types to do this for */ +} *asn1_module; + void generate_type (const Symbol *); void generate_constant (const Symbol *); void generate_type_encode (const Symbol *); diff --git a/lib/asn1/gen_template.c b/lib/asn1/gen_template.c index 329acef1d..a5b9b6e12 100644 --- a/lib/asn1/gen_template.c +++ b/lib/asn1/gen_template.c @@ -181,6 +181,8 @@ bitstring_symbol(const char *basename, const Type *t) +/* XXX Make sure this is sorted by `type' and can just index this by type */ +/* XXX Make this const! */ struct { enum typetype type; const char *(*symbol_name)(const char *, const Type *); @@ -932,6 +934,7 @@ generate_template_type(const char *varname, free(szt); + /* XXX Accidentally O(N^2)? */ d = tlist_find_dup(tl); if (d) { #if 0