This is a multi-part message in MIME format.
--------------060404060401020509010805
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

I needed to have a routine to convert the data stored in an ASN1_TYPE
structure to an ASCII string. After finding that no one on the net
seemed to have the answer I went and did some research. This is what I
came up with for an answer. If any one sees anything wrong with it I
would love to know about it and will make suitable adjustments. I will
probably submit the change to the OpenSSL project for hopeful inclusion.


Peace,
Chuck Wegrzyn

--------------060404060401020509010805
Content-Type: text/plain;
name="asn1type.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="asn1type.c"

#include
#include
#include
#include
#include

static void error(char *msg)
{
// print out message...
printf(msg);
exit(1);
}

void ASN1_TYPE_print(BIO *bio,ASN1_TYPE *ptr)
{
// memory bio to collect the output.
char objbuf[80];
const char *ln;

// Collect the things from the ASN1_TYPE structure
switch(ptr->type)
{
case V_ASN1_BOOLEAN:
BIO_puts(bio, ptr->value.boolean ? "true" : "false");
break;

case V_ASN1_INTEGER:
BIO_puts(bio,i2s_ASN1_INTEGER(NULL,ptr->value.integer));
break;

case V_ASN1_ENUMERATED:
BIO_puts(bio,i2s_ASN1_INTEGER(NULL,ptr->value.enumerated));
break;

case V_ASN1_NULL:
BIO_puts(bio,"NULL");
break;

case V_ASN1_UTCTIME:
ASN1_UTCTIME_print(bio,ptr->value.utctime);
break;

case V_ASN1_GENERALIZEDTIME:
ASN1_GENERALIZEDTIME_print(bio,ptr->value.generalizedtime);
break;

case V_ASN1_OBJECT:
ln = OBJ_nid2ln(OBJ_obj2nid(ptr->value.object));
if( !ln ) ln = "";
OBJ_obj2txt(objbuf,sizeof(objbuf),ptr->value.object,1);
BIO_puts(bio,objbuf);
break;

default :
ASN1_STRING_print_ex(bio, ptr->value.visiblestring,
ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE);
break;
}

}

--------------060404060401020509010805--
__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager majordomo@openssl.org