keyBag->tokenCAs = p12dcx->tokenCAs;
sec_pkcs12_decoder_convert_old_key(SEC_PKCS12DecoderContext *p12dcx,				   void *key, PRBool isEspvk){    sec_PKCS12SafeBag *keyBag;    SECOidData *oid;    SECOidTag keyTag;    SECItem *keyID, *nickName, *newNickName;    if(!p12dcx || p12dcx->error || !key) {	return NULL;    }    newNickName =(SECItem *)PORT_ArenaZAlloc(p12dcx->arena, sizeof(SECItem));    keyBag = (sec_PKCS12SafeBag *)PORT_ArenaZAlloc(p12dcx->arena, 						   sizeof(sec_PKCS12SafeBag));    if(!keyBag || !newNickName) {	PORT_SetError(SEC_ERROR_NO_MEMORY);	return NULL;    }    keyBag->swapUnicodeBytes = p12dcx->swapUnicodeBytes;    keyBag->slot = p12dcx->slot;    keyBag->arena = p12dcx->arena;    keyBag->pwitem = p12dcx->pwitem;    keyBag->oldBagType = PR_TRUE;    keyTag = (isEspvk) ? SEC_OID_PKCS12_V1_PKCS8_SHROUDED_KEY_BAG_ID :			 SEC_OID_PKCS12_V1_KEY_BAG_ID;    oid = SECOID_FindOIDByTag(keyTag);    if(!oid) {	PORT_SetError(SEC_ERROR_NO_MEMORY);	return NULL;    }    if(SECITEM_CopyItem(p12dcx->arena, &keyBag->safeBagType, &oid->oid) 			!= SECSuccess) {	PORT_SetError(SEC_ERROR_NO_MEMORY);	return NULL;    }    if(isEspvk) {	SEC_PKCS12ESPVKItem *espvk = (SEC_PKCS12ESPVKItem *)key;	keyBag->safeBagContent.pkcs8ShroudedKeyBag  = 					espvk->espvkCipherText.pkcs8KeyShroud;	nickName = &(espvk->espvkData.uniNickName); 	if(!espvk->espvkData.assocCerts || !espvk->espvkData.assocCerts[0]) {	    PORT_SetError(SEC_ERROR_PKCS12_CORRUPT_PFX_STRUCTURE);	    return NULL;	}	keyID = &espvk->espvkData.assocCerts[0]->digest;    } else {	SEC_PKCS12PrivateKey *pk = (SEC_PKCS12PrivateKey *)key;	keyBag->safeBagContent.pkcs8KeyBag = &pk->pkcs8data;	nickName= &(pk->pvkData.uniNickName);	if(!pk->pvkData.assocCerts || !pk->pvkData.assocCerts[0]) {	    PORT_SetError(SEC_ERROR_PKCS12_CORRUPT_PFX_STRUCTURE);	    return NULL;	}	keyID = &pk->pvkData.assocCerts[0]->digest;    }    if(nickName->len) {	if(nickName->len >= 2) {	    if(nickName->data[0] && nickName->data[1]) {		if(!sec_pkcs12_convert_item_to_unicode(p12dcx->arena, newNickName, 					nickName, PR_FALSE, PR_FALSE, PR_TRUE)) {		    PORT_SetError(SEC_ERROR_NO_MEMORY);		    return NULL;		}		nickName = newNickName;	    } else if(nickName->data[0] && !nickName->data[1]) {		unsigned int j = 0;		unsigned char t;		for(j = 0; j < nickName->len; j+=2) {		    t = nickName->data[j+1];		    nickName->data[j+1] = nickName->data[j];		    nickName->data[j] = t;		}	    }	} else {	    if(!sec_pkcs12_convert_item_to_unicode(p12dcx->arena, newNickName, 					nickName, PR_FALSE, PR_FALSE, PR_TRUE)) {		PORT_SetError(SEC_ERROR_NO_MEMORY);		return NULL;	    }	    nickName = newNickName;	}    }    if(sec_pkcs12_decoder_set_attribute_value(keyBag,					      SEC_OID_PKCS9_FRIENDLY_NAME,					      nickName) != SECSuccess) {	return NULL;    }	    if(sec_pkcs12_decoder_set_attribute_value(keyBag,SEC_OID_PKCS9_LOCAL_KEY_ID,					keyID) != SECSuccess) {	return NULL;    }    return keyBag;}