Hello, Nelson.
On Mon, 10 Oct 2009, Nelson B Bolyard wrote:
On 2009-10-05 02:20 PDT, Konstantin Andreev wrote:
I need to decode some DER-encoded ASN1 CHOICE, but I can't manage this in a
reasonable way.
FYI, the documentation on NSS's ASN.1 encoder and its two decoders is at
http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn1.html
It documents SEC_ASN1_CHOICE. I believe the info you want is there, ...
No, it is not. I have read TN1 before posting here. It has only subtle clue about CHOICE
decoding, here it is: "Subsequent templates specify a custom identifier for each
possible component type in the size parameter".
The feature itself even not mentioned. The most important parts of feature are
not mentioned too:
struct {
int which;
} decodedChoice;
{ SEC_ASN1_CHOICE, 0, 0, offsetof( decodedChoice, which ) },
The TN1 ought to be updated.
... but I will also add some info here.
Thank you for this invaluable thorough example. This is exactly what I was
looking for.
Best regards,
--
Konstantin Andreev, software engineer.
Swemel JSC
This is how I have managed this at the moment (pseudo-code):
---( begin code )---------
struct {
SECItem choice1;
SECItem choice2;
...
SECItem choiceN;
}
decodedChoice;
Try this instead:
struct {
SECItem choice;
int which;
} 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 }
};
Try this:
{ SEC_ASN1_CHOICE, 0, 0, offsetof( decodedChoice, which ) },
{ SEC_ASN1_INTEGER, offsetof( decodedChoice, choice ), 0, 1 },
{ SEC_ASN1_NULL, offsetof( decodedChoice, choice ), 0, 2 },
...
{ SEC_ASN1_BOOLEAN, offsetof( decodedChoice, choice ), 0, N },
{ 0 }
[ ... SKIP ... ]
--
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto