Dr. Stephen Henson wrote:
> On Sun, Jun 23, 2002, Michael Voucko wrote:
> 
> 
>>Hi list,
>>
>>still trying to get all the ASN1 stuff done I need.
>>My current problem is caused by an extra tag/length pair when using my
>>DIRECTORY_STRING implementation.
>>
>>The ASN1 definition is like this
>>
>>DirectoryString ::= CHOICE {
>>     printableString PrintableString
>>     teletexString TeletexString
>>     utf8String UTF8String
>>     bmpString BMPString
>>     universalString UniversalString
>>}
>>
>>My definition looks like this
>>
>><snip>
>>ASN1_CHOICE(DIRECTORY_STRING) = {
>>     ASN1_SIMPLE(DIRECTORY_STRING, value.PrintableString, ASN1_PRINTABLESTRING),
>>     ASN1_SIMPLE(DIRECTORY_STRING, value.TeletextString, ASN1_T61STRING),
>>     ASN1_SIMPLE(DIRECTORY_STRING, value.UTF8String, ASN1_UTF8STRING),
>>     ASN1_SIMPLE(DIRECTORY_STRING, value.BMPString, ASN1_BMPSTRING),
>>     ASN1_SIMPLE(DIRECTORY_STRING, value.UniversalString, ASN1_UNIVERSALSTRING)
>>} ASN1_CHOICE_END(DIRECTORY_STRING)
>>
>>IMPLEMENT_ASN1_FUNCTIONS(DIRECTORY_STRING)
>></snip>
>>
>>The declaration of the corresponding struct looks like this
>>
>><snip>
>>typedef struct directory_string_st {
>>
>>#define DIRSTR_PRINTABLE    0
>>#define DIRSTR_TELETEXT     1
>>#define DIRSTR_UTF8         2
>>#define DIRSTR_BMP          3
>>#define DIRSTR_UNIVERSAL    4
>>
>>     int type;
>>     union {
>>         ASN1_PRINTABLESTRING *PrintableString;
>>         ASN1_T61STRING *TeletextString;
>>         ASN1_UTF8STRING *UTF8String;
>>         ASN1_BMPSTRING *BMPString;
>>         ASN1_UNIVERSALSTRING *UniversalString;
>>     } value;
>>} DIRECTORY_STRING;
>>
>>DECLARE_ASN1_FUNCTIONS(DIRECTORY_STRING)
>>
>></snip>
>>
>>
>>When using the DIRECTORYSTRING type in my source code like this to create a 
>>DIRECTORYSTRING containing a ASN1_PRINTABLE
>>
>><snip>
>>     directoryString = DIRECTORYSTRING_new();
>>
>>     directoryString->type = DIRSTR_PRINTABLE;
>>     mString = (ASN1_STRING *) ASN1_PRINTABLE_new();
>>     if (!mString)
>>             goto error_exit;
>>     if (!(ASN1_STRING_set(mString, aValue, -1)))
>>     {
>>         goto error_exit;
>>     }
>>     directoryString->value.PrintableString = (ASN1_PRINTABLESTRING *) mString;
>>
>>     blobLen = i2d_DIRECTORYSTRING(directoryString, NULL);
>>     blob = (unsigned char *) malloc(blobLen);
>>     if (!blob)
>>         goto error_exit;
>>     tmpPtr = blob;
>>     blobLen = i2d_DIRECTORYSTRING(directoryString, &tmpPtr);
>></snip>
>>
>>I end up with an extra tag 0x0c and length byte.
>>
>>Can anybody point me to my problem?
>>
> 
> 
> Your problem above is that you have defined ASN1 functions using
> DIRECTORY_STRING but the functions you call have DIRECTORYSTRING
> in them which happens to be already defined in OpenSSL. These
> have difference structures and are being confused as a result.
> 
> If you use DIRECTORY_STRING for the relevant calls then your
> code works OK.
> 
> Though as I mentioned in the other message the DirectoryString
> type is already defined in OpenSSL.
> 
> Steve.

Thanks again for your valuable help

   Michael

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to