From 16179383fb0dd80d66e26f35df960cbcc81da58c Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 14 Nov 2022 17:27:06 +1100 Subject: [PATCH] asn1: note IMPLICIT CHOICE promoted to EXPLICIT Record when a CHOICE field is promoted from IMPLICIT to EXPLICIT and convey this in the ASN.1 compiler's JSON output, so that other tools (e.g. which have a representation isomorphic to the original ASN.1) may use it. --- lib/asn1/asn1parse.y | 4 +++- lib/asn1/gen.c | 3 +++ lib/asn1/symbol.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/asn1/asn1parse.y b/lib/asn1/asn1parse.y index f6f6ec0e5..d9e3fba2d 100644 --- a/lib/asn1/asn1parse.y +++ b/lib/asn1/asn1parse.y @@ -1432,8 +1432,10 @@ TaggedType : Tag tagenv Type * IMPLICIT tags of CHOICE types are EXPLICIT * instead. */ - if (t->type == TChoice) + if (t->type == TChoice) { + $$->implicit_choice = 1; $$->tag.tagenv = TE_EXPLICIT; + } if($3->type == TTag && $2 == TE_IMPLICIT) { $$->subtype = $3->subtype; free($3); diff --git a/lib/asn1/gen.c b/lib/asn1/gen.c index f55c636b7..af543d966 100644 --- a/lib/asn1/gen.c +++ b/lib/asn1/gen.c @@ -1529,6 +1529,9 @@ define_type(int level, const char *name, const char *basename, Type *pt, Type *t fprintf(jsonfile, "\"ttype\":\"TeletexString\",\"ctype\":\"heim_general_string\""); break; case TTag: + if (t->implicit_choice) { + fprintf(jsonfile, "\"desired_tagenv\":\"IMPLICIT\","); + } fprintf(jsonfile, "\"tagclass\":\"%s\",\"tagvalue\":%d,\"tagenv\":\"%s\",\n", tagclassnames[t->tag.tagclass], t->tag.tagvalue, t->tag.tagenv == TE_EXPLICIT ? "EXPLICIT" : "IMPLICIT"); diff --git a/lib/asn1/symbol.h b/lib/asn1/symbol.h index 8a24e2515..bce2e1fe4 100644 --- a/lib/asn1/symbol.h +++ b/lib/asn1/symbol.h @@ -200,6 +200,7 @@ struct type { struct range *range; struct constraint_spec *constraint; unsigned long id; + unsigned int implicit_choice:1; }; typedef struct type Type;