Andrzej,
Call i2d_ASN1_INTEGER to DER-encode an ASN.1 INTEGER. Pass 0 or NULL as the second argument to i2d_ASN1_INTEGER to determine the length of the DER-encoded INTEGER. If you pass a non-zero value as the second argument to i2d_ASN1_INTEGER, the function will DER-encode the INTEGER and increment the second argument to the first byte after the DER-encoded INTEGER. Looks like (I did not compile this code):
ASN1_INTEGER * integer; /* points to an ASN1_INTEGER */
unsigned char * der = NULL;
unsigned char * derNext = NULL;
int length = 0;
length = i2d_ASN1_INTEGER(integer, 0);
if (length <= 0)
goto error;
der = OPENSSL_malloc(length);
if (!der)
goto error;
/*
Because i2d functions modify their second argument, use the variable
derNext.
*/
derNext = der;
length = i2d_ASN1_INTEGER(integer, &derNext);
if (length <= 0)
goto error;
Frank
"Andrzej Posiadala" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED] 02/11/2004 07:57 AM
|
To: [EMAIL PROTECTED] cc: Subject: How to convert internal ASN1_INTEGER into little endian content octets |
Hi ,
i'm trying to convert ASN1_INTEGER (specifically certificate serial
number) into its DER representation.
I'm using i2c_ASN1_INTEGER - and if it's the right function - then I don't
understand why it moves a pointer passed to it as second parameter behind
reserved memory.
Here is what I'm doing:
int size;
ASN1_INTEGER * serial;
unsigned char * serialNumberDER;
size = i2c_ASN1_INTEGER(serial, NULL);
serialNumberDER = new unsigned char[*size];
size = i2c_ASN1_INTEGER(serial, & serialNumberDER);
The function has this code at the end:
*pp+=ret;
where pp is a pointer to serialNumberDER, so in effect it moves
serialNumberDER behind created array of unsigned char.
Please, explain it to me.
Thanks in advance.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]