Hello.
I need to decode some DER-encoded ASN1 CHOICE, but I can't manage this in a
reasonable way.
This is how I have managed this at the moment (pseudo-code):
---( begin code )---------
struct {
SECItem choice1;
SECItem choice2;
...
SECItem choiceN;
}
decodedChoice;
SEC_ASN1Template choiceTemplate[] =
{
{ SEC_ASN1_CHOICE },
{ SEC_ASN1_INTEGER, offsetof( decodedChoice, choice1 ) },
{ SEC_ASN1_NULL, offsetof( decodedChoice, choice2 ) },
...
{ SEC_ASN1_BOOLEAN, offsetof( decodedChoice, choiceN ) },
{ 0 }
};
SEC_QuickDERDecodeItem( arena, & decodedChoice, choiceTemplate, src );
// then I must walk through the choices to find out which one was catched:
if( choice1.data ) { ... }
else if( choice2.data ) { ... }
...
else /* choiceN.data */ { ... }
---( end code )---------
The drawbacks are:
-- I have a lot of SECItems: choice1, ..., choiceN.
I would prefer the single SECItem to put the choice in.
-- I have a lot of if/if else/if else/else's after SEC_QuickDERDecodeItem.
I would prefer to have a single variable which receives catched ASN1 tag,
or something like that.
Could you, please, advice, how can I decode CHOICE more reasonable than shown
above ?
Best regards,
--
Konstantin Andreev, software engineer.
Swemel JSC
--
dev-tech-crypto mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-crypto