if(cert) { CERT_DestroyCertificate(cert); }
P12U_ExportPKCS12Object(char *nn, char *outfile, PK11SlotInfo *inSlot,			secuPWData *slotPw, secuPWData *p12FilePw){    SEC_PKCS12ExportContext *p12ecx = NULL;    SEC_PKCS12SafeInfo *keySafe = NULL, *certSafe = NULL;    SECItem *pwitem = NULL;    p12uContext *p12cxt = NULL;    CERTCertificate *cert = NULL;    if (P12U_InitSlot(inSlot, slotPw) != SECSuccess) {	SECU_PrintError(progName,"Failed to authenticate to \"%s\"",			  PK11_GetSlotName(inSlot));	pk12uErrno = PK12UERR_PK11GETSLOT;	goto loser;    }    cert = PK11_FindCertFromNickname(nn, slotPw);    if(!cert) {	SECU_PrintError(progName,"find cert by nickname failed");	pk12uErrno = PK12UERR_FINDCERTBYNN;	return;    }    if (!cert->slot) {	SECU_PrintError(progName,"cert does not have a slot");	pk12uErrno = PK12UERR_FINDCERTBYNN;	goto loser;    }    /*	Password to use for PKCS12 file.  */    pwitem = P12U_GetP12FilePassword(PR_TRUE, p12FilePw);    if(!pwitem) {	goto loser;    }    p12ecx = SEC_PKCS12CreateExportContext(NULL, NULL, cert->slot, slotPw);    if(!p12ecx) {	SECU_PrintError(progName,"export context creation failed");	pk12uErrno = PK12UERR_EXPORTCXCREATE;	goto loser;    }    if(SEC_PKCS12AddPasswordIntegrity(p12ecx, pwitem, SEC_OID_SHA1)       != SECSuccess) {	SECU_PrintError(progName,"PKCS12 add password integrity failed");	pk12uErrno = PK12UERR_PK12ADDPWDINTEG;	goto loser;    }    keySafe = SEC_PKCS12CreateUnencryptedSafe(p12ecx);    if(/*!SEC_PKCS12IsEncryptionAllowed() || */ PK11_IsFIPS()) {	certSafe = keySafe;    } else {	certSafe = SEC_PKCS12CreatePasswordPrivSafe(p12ecx, pwitem,			SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_40_BIT_RC2_CBC);    }    if(!certSafe || !keySafe) {	SECU_PrintError(progName,"key or cert safe creation failed");	pk12uErrno = PK12UERR_CERTKEYSAFE;	goto loser;    }    if(SEC_PKCS12AddCertAndKey(p12ecx, certSafe, NULL, cert,			CERT_GetDefaultCertDB(), keySafe, NULL, PR_TRUE, pwitem,			SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_3KEY_TRIPLE_DES_CBC)			!= SECSuccess) {	SECU_PrintError(progName,"add cert and key failed");	pk12uErrno = PK12UERR_ADDCERTKEY;	goto loser;    }    p12cxt = p12u_InitFile(PR_FALSE, outfile);     if(!p12cxt) {	SECU_PrintError(progName,"Initialization failed: %s", outfile);	pk12uErrno = PK12UERR_INIT_FILE;	goto loser;    }    if(SEC_PKCS12Encode(p12ecx, p12u_WriteToExportFile, p12cxt)			!= SECSuccess) {	SECU_PrintError(progName,"PKCS12 encode failed");	pk12uErrno = PK12UERR_ENCODE;	goto loser;    }    p12u_DestroyExportFileInfo(&p12cxt, PR_FALSE);    SECITEM_ZfreeItem(pwitem, PR_TRUE);    CERT_DestroyCertificate(cert);    fprintf(stdout, "%s: PKCS12 EXPORT SUCCESSFUL\n", progName);    SEC_PKCS12DestroyExportContext(p12ecx);    return;loser:    SEC_PKCS12DestroyExportContext(p12ecx);    if (slotPw)	PR_Free(slotPw->data);    if (p12FilePw)	PR_Free(p12FilePw->data);    if(cert) {	CERT_DestroyCertificate(cert);    }    p12u_DestroyExportFileInfo(&p12cxt, PR_TRUE);    if(pwitem) {	SECITEM_ZfreeItem(pwitem, PR_TRUE);    }    p12u_DoPKCS12ExportErrors();    return;}