On Sat, Mar 19, 2005, Eric Alata wrote: > Thank you Stephen for your reply. > > As expected in your answer, I have used > ASN1_DECLARE_ITEM(TA) just before > ASN1_CHOICE(TA). Now, it compiles. > > I believe to understant why this structure > is ambiguous. Only, I need this field f2. > If I write: > > TA ::= CHOICE { > f1 SET OF TA, > f2 [10] TA, > f3 INTEGER > } > > 1 struct _ta_st TA; > 2 > 3 struct _ta_st { > 4 int type; > 5 union { > 6 STACK_OF(TA) *f1; > 7 TA *f2; > 8 ASN1_INTEGER *f3; > 9 } value; > 10 }; > 11 > 12 ASN1_DECLARE_ITEM(TA) > 13 ASN1_CHOICE(TA) = { > 14 ASN1_SET_OF(TA, value.f1, TA), > 15 ASN1_EXP(TA, value.f2, TA, 10), > 16 ASN1_SIMPLE(TA, value.f3, ASN1_INTEGER) > 17 } ASN1_CHOICE_END(TA) > > I think that the ambiquity is not present any more. > Is it correct ? > > I will see how it works with ASN1_DECLARE_ITEM(TA). > It compiles and the structure seems to be correctely > initialised. >
Yes that will work though it is more usual to use [0]. To see why the original is ambiguous you have to consider how a decoder would handle it: > TA ::= CHOICE { > f1 SET OF TA, > f2 TA, > f3 INTEGER Suppose "x" is of type TA and choice f2 is wanted. Suppose further that this type f2 itself is of type f1. The decoder will just see the underlying type which is INTEGER. However this would look eactly the same as if x was of type f3. So the decoder has no way to distinguish these two cases. By adding the context specific tag it will see that tag and know that f2 is used and the ambiguity is removed. You should also note that SET OF ends up sorting in lexical order when it is used (i.e. it doesn't preserve the original ordering): this can be slow to encode. If you used SEQUENCE OF it wouldn't sort it and does preserve the ordering. Steve. -- Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage OpenSSL project core developer and freelance consultant. Funding needed! Details on homepage. Homepage: http://www.drh-consultancy.demon.co.uk ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]