if(SEC_ASN1DecodeItem(NULL, &avaValue, theTemplate, derAVAValue)
newarena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); if (!newarena) { return NULL; } if(SEC_QuickDERDecodeItem(newarena, &avaValue, theTemplate, derAVAValue)
CERT_DecodeAVAValue(SECItem *derAVAValue){          SECItem          *retItem;     const SEC_ASN1Template *theTemplate       = NULL;          PRBool            convertUCS4toUTF8 = PR_FALSE;          PRBool            convertUCS2toUTF8 = PR_FALSE;          SECItem           avaValue          = {siBuffer, 0};     if(!derAVAValue) {	return NULL;    }    switch(derAVAValue->data[0]) {	case SEC_ASN1_UNIVERSAL_STRING:	    convertUCS4toUTF8 = PR_TRUE;	    theTemplate = SEC_UniversalStringTemplate;	    break;	case SEC_ASN1_IA5_STRING:	    theTemplate = SEC_IA5StringTemplate;	    break;	case SEC_ASN1_PRINTABLE_STRING:	    theTemplate = SEC_PrintableStringTemplate;	    break;	case SEC_ASN1_T61_STRING:	    theTemplate = SEC_T61StringTemplate;	    break;	case SEC_ASN1_BMP_STRING:	    convertUCS2toUTF8 = PR_TRUE;	    theTemplate = SEC_BMPStringTemplate;	    break;	case SEC_ASN1_UTF8_STRING:	    /* No conversion needed ! */	    theTemplate = SEC_UTF8StringTemplate;	    break;	default:	    return NULL;    }    PORT_Memset(&avaValue, 0, sizeof(SECItem));    if(SEC_ASN1DecodeItem(NULL, &avaValue, theTemplate, derAVAValue) 				!= SECSuccess) {	return NULL;    }    if (convertUCS4toUTF8) {	unsigned int   utf8ValLen = avaValue.len * 3;	unsigned char *utf8Val    = (unsigned char*)PORT_ZAlloc(utf8ValLen);	if(!PORT_UCS4_UTF8Conversion(PR_FALSE, avaValue.data, avaValue.len,				     utf8Val, utf8ValLen, &utf8ValLen)) {	    PORT_Free(utf8Val);	    PORT_Free(avaValue.data);	    return NULL;	}	PORT_Free(avaValue.data);	avaValue.data = utf8Val;	avaValue.len = utf8ValLen;    } else if (convertUCS2toUTF8) {	unsigned int   utf8ValLen = avaValue.len * 3;	unsigned char *utf8Val    = (unsigned char*)PORT_ZAlloc(utf8ValLen);	if(!PORT_UCS2_UTF8Conversion(PR_FALSE, avaValue.data, avaValue.len,				     utf8Val, utf8ValLen, &utf8ValLen)) {	    PORT_Free(utf8Val);	    PORT_Free(avaValue.data);	    return NULL;	}	PORT_Free(avaValue.data);	avaValue.data = utf8Val;	avaValue.len = utf8ValLen;    }    retItem = SECITEM_DupItem(&avaValue);    PORT_Free(avaValue.data);    return retItem;}