I've got the next code like the x_val.c, and but when I introduce the sequence in the asn.1 type I get an error.
What's the problem?
Thanks in advance,
Regards,
Antonio.
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/asn1.h>
#include <openssl/asn1_mac.h>
#include "cryptlib.h"
//SEQUENCE
typedef struct X_val_st
{
ASN1_INTEGER *notBefore;
ASN1_INTEGER *notAfter;
} X_VAL;
X_VAL *X_VAL_new(void);
void X_VAL_free(X_VAL *a);
int i2d_X_VAL(X_VAL *a, unsigned char **pp)
{
M_ASN1_I2D_vars(a);
M_ASN1_I2D_len(a->notBefore,i2d_ASN1_INTEGER);
M_ASN1_I2D_len(a->notAfter,i2d_ASN1_INTEGER);
M_ASN1_I2D_seq_total();
M_ASN1_I2D_put(a->notBefore,i2d_ASN1_INTEGER);
M_ASN1_I2D_put(a->notAfter,i2d_ASN1_INTEGER);
M_ASN1_I2D_finish();
}
X_VAL *d2i_X_VAL(X_VAL **a, unsigned char **pp, long length)
{
M_ASN1_D2I_vars(a,X_VAL *,X_VAL_new);
M_ASN1_D2I_Init();
M_ASN1_D2I_start_sequence();
M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_INTEGER);
M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_INTEGER);
M_ASN1_D2I_Finish(a,X_VAL_free,333);
}
X_VAL *X_VAL_new(void)
{
X_VAL *ret=NULL;
ASN1_CTX c;
M_ASN1_New_Malloc(ret,X_VAL);
M_ASN1_New(ret->notBefore,M_ASN1_INTEGER_new);
M_ASN1_New(ret->notAfter,M_ASN1_INTEGER_new);
return(ret);
M_ASN1_New_Error(333);
}
void X_VAL_free(X_VAL *a)
{
if (a == NULL) return;
M_ASN1_TIME_free(a->notBefore);
M_ASN1_TIME_free(a->notAfter);
OPENSSL_free(a);
}
int main()
{
//------------------------
// ASN.1 type y SEQUENCE
//------------------------
printf("ASN.1 type and SEQUECE\n");
ASN1_TYPE *atS=NULL;
unsigned char *der31=NULL;
ASN1_INTEGER *not11,*not22;
not11=ASN1_INTEGER_new();
not22=ASN1_INTEGER_new();
ASN1_INTEGER_set(not11,1243);
ASN1_INTEGER_set(not22,1555);
long px1=ASN1_INTEGER_get(not11);
printf("Integer: %d\n",px1);
X_VAL *xVal1=X_VAL_new();
xVal->notAfter=not11;
xVal->notBefore=not22;
atS=ASN1_TYPE_new();
ASN1_TYPE_set(atS,V_ASN1_SEQUENCE,(char *)xVal1);
int londer1=i2d_ASN1_TYPE(atS,NULL);
der31=(unsigned char *)OPENSSL_malloc(londer1);
unsigned char* tmpder31 = der31;
londer1= i2d_ASN1_TYPE(atS,&tmpder31);
ASN1_TYPE *atype21=NULL;
atype21=d2i_ASN1_TYPE(NULL,&der31,londer1);
if ((atype21->type)==V_ASN1_SEQUENCE)
printf("OK\n");
return 0;
}
--
------------------------------------------------------
Antonio Ruiz Martínez
Facultad de Informática-Universidad de Murcia
30001 Murcia - España (Spain)
Telf: +34-968-364644 e-mail: [EMAIL PROTECTED]
------------------------------------------------------