Hi,
I am trying to create and parse some ASN1 objects, but so far I did not
succeed. Here is my piece of code:
unsigned char *res;
int num;
long ret;
unsigned char *prstr = "hello";
ASN1_BIT_STRING *str;
FILE fp;
res = (unsigned char *) malloc( sizeof(unsigned char)*10000 );
str = ASN1_BIT_STRING_new();
str->length = strlen( prstr );
str->type = 19; // printablestring
str->data = prstr;
ret = i2d_ASN1_BIT_STRING( str, &res );
// here it seems to be OK, as I got 8 in ret
fp = fopen( "str.out", "wb" );
num = fwrite( res, sizeof(unsigned char), ret, fp );
fclose(fp);
// but here I got 8 0s in str.out
On the other hand I am unable to parse pre-created ASN1 objects, too:
Here is what I have tried:
ASN1_X509 *x509struct;
ASN1_X509 *x509;
fp = fopen( CERTFILE, "rb" ); // this is a proper certificate
num = fread( res, sizeof(unsigned char), 10000, fp );
fclose( fp );
x509struct = ASN1_X509_new();
x509 = d2i_ASN1_X509( &x509struct, &res, num );
if( x509 == NULL ) printf( "error" );
// ... and x509 is NULL.
Obviously, I am missing something important, but what?
I am using SSLeay 0.9.0 on NT 4.0.
Thanx in advance,
Zoli
+-------------------------------------------------------------------------+
| Administrative requests should be sent to [EMAIL PROTECTED] |
| List service provided by Open Software Associates, http://www.osa.com/ |
+-------------------------------------------------------------------------+