Hi,

I have made the change. Now, the CHOICE looks like:

1  ASN1_CHOICE(G) = {
2        ASN1_EX_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 0, G, value.g_1, 
H_BODY),
3        ASN1_EX_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 1, G, value.g_2, 
I_BODY)
4  } ASN1_CHOICE_END(G)

It works fine. But, if I understand, everywhere I want to use H, I must use the
ASN1_EX_TYPE definition?
So, the declarations at the end of this message are correct ?

Thank you very much to have helped me. Now I can continue to work!

Thanks.
Eric



Here are outputs and the test program.

     -----


30:00110000   a:00001010  60:01100000   3:00000011
 2:00000010   1:00000001  12:00010010  61:01100001
 3:00000011   4:00000100   1:00000001  34:00110100
---

60:01100000   3:00000011   2:00000010   1:00000001
7b:01111011


     -----


#define H_BODY ASN1_INTEGER
#define I_BODY ASN1_OCTET_STRING


typedef struct _G {
        int type;
        union {
                H_BODY *g_1;
                I_BODY *g_2;
        } value;
} G;


#define G_1 0
#define G_2 1


typedef struct _F {
        H_BODY *f_1;
        I_BODY *f_2;
} F;


ASN1_ITEM_TEMPLATE(I) =
        ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 1, I, 
I_BODY)
ASN1_ITEM_TEMPLATE_END(I)


ASN1_ITEM_TEMPLATE(H) =
        ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 0, H, 
H_BODY)
ASN1_ITEM_TEMPLATE_END(H)


ASN1_CHOICE(G) = {
        ASN1_EX_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 0, G, value.g_1, 
H_BODY),
        ASN1_EX_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 1, G, value.g_2, 
I_BODY)
} ASN1_CHOICE_END(G)


ASN1_SEQUENCE(F) = {
        ASN1_SIMPLE(F, f_1, H),
        ASN1_SIMPLE(F, f_2, I)
} ASN1_SEQUENCE_END(F)


IMPLEMENT_ASN1_FUNCTIONS(G)
IMPLEMENT_ASN1_FUNCTIONS(I_BODY)
IMPLEMENT_ASN1_FUNCTIONS(F)


void hex2bin(int bin, char *str) {
        unsigned int mask;

        mask = 0x80;
        while (mask) {
                if (bin & mask)
                        *str = '1';
                else
                        *str = '0';
                str++;
                mask >>= 1;
        }
        *str = 0;
}



int main(void) {
        unsigned char *buffer;
        unsigned char string[8];
        int j;
        int i;
        G *f;
        G *g;
        F *f1;
        F *f2;

        f1 = F_new();
        ASN1_INTEGER_set(f1->f_1, 0x12);
        ASN1_INTEGER_set(f1->f_2, 0x34);

        buffer = NULL;
        i = i2d_F(f1, &buffer);

        for (j = 0; j < i; j++) {
                int n = buffer[j] & 0xFF;
                if (j % 4 == 0) {
                        printf("\n");
                }
                hex2bin(n, string);
                printf("%2x:%s  ", n, string);
        }

        f2 = d2i_F(NULL, &buffer, i);

        if (f2 == NULL) {
                printf("Error\n");
        } else {
                F_free(f2);
        }
        printf("\n");

        printf("---\n");

        g = G_new();
        g->type = G_1;
        g->value.g_1 = ASN1_INTEGER_new();
        ASN1_INTEGER_set(g->value.g_1, 123);

        buffer = NULL;
        i = i2d_G(g, &buffer);

        for (j = 0; j < i; j++) {
                int n = buffer[j] & 0xFF;
                if (j % 4 == 0) {
                        printf("\n");
                }
                hex2bin(n, string);
                printf("%2x:%s  ", n, string);
        }
        printf("\n");

        f = d2i_G(NULL, &buffer, i);

        if (f == NULL) {
                printf("Error\n");
        } else {
                G_free(g);
        }

        return 0;
}
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to