default: ASN1err(ASN1_F_D2I_ASN1_TYPE,ASN1_R_BAD_TYPE); goto err;
ASN1_TYPE *d2i_ASN1_TYPE(ASN1_TYPE **a, unsigned char **pp, long length)	{	ASN1_TYPE *ret=NULL;	unsigned char *q,*p,*max;	int inf,tag,xclass;	long len;	if ((a == NULL) || ((*a) == NULL))		{		if ((ret=ASN1_TYPE_new()) == NULL) goto err;		}	else		ret=(*a);	p= *pp;	q=p;	max=(p+length);	inf=ASN1_get_object(&q,&len,&tag,&xclass,length);	if (inf & 0x80) goto err;		ASN1_TYPE_component_free(ret);	switch (tag)		{	case V_ASN1_NULL:		p=q;		ret->value.ptr=NULL;		break;	case V_ASN1_INTEGER:		if ((ret->value.integer=			d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_ENUMERATED:		if ((ret->value.enumerated=			d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_BIT_STRING:		if ((ret->value.bit_string=			d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_OCTET_STRING:		if ((ret->value.octet_string=			d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_VISIBLESTRING:		if ((ret->value.visiblestring=			d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_UTF8STRING:		if ((ret->value.utf8string=			d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_OBJECT:		if ((ret->value.object=			d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_PRINTABLESTRING:		if ((ret->value.printablestring=			d2i_ASN1_PRINTABLESTRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_T61STRING:		if ((ret->value.t61string=			M_d2i_ASN1_T61STRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_IA5STRING:		if ((ret->value.ia5string=			M_d2i_ASN1_IA5STRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_GENERALSTRING:		if ((ret->value.generalstring=			M_d2i_ASN1_GENERALSTRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_UNIVERSALSTRING:		if ((ret->value.universalstring=			M_d2i_ASN1_UNIVERSALSTRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_BMPSTRING:		if ((ret->value.bmpstring=			M_d2i_ASN1_BMPSTRING(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_UTCTIME:		if ((ret->value.utctime=			d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_GENERALIZEDTIME:		if ((ret->value.generalizedtime=			d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL)			goto err;		break;	case V_ASN1_SET:	case V_ASN1_SEQUENCE:		/* Sets and sequences are left complete */		if ((ret->value.set=ASN1_STRING_new()) == NULL) goto err;		ret->value.set->type=tag;		len+=(q-p);		if (!ASN1_STRING_set(ret->value.set,p,(int)len)) goto err;		p+=len;		break;	default:		ASN1err(ASN1_F_D2I_ASN1_TYPE,ASN1_R_BAD_TYPE);		goto err;		}	ret->type=tag;	if (a != NULL) (*a)=ret;	*pp=p;	return(ret);err:	if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_TYPE_free(ret);	return(NULL);	}