if (certDER) PR_Write(outFile, certDER->data, certDER->len);
if (certDER) { if (ascii) { PR_fprintf(outFile, "%s\n%s\n%s\n", NS_CERT_HEADER, BTOA_DataToAscii(certDER->data, certDER->len), NS_CERT_TRAILER); } else { PR_Write(outFile, certDER->data, certDER->len); } }
CreateCert(	CERTCertDBHandle *handle, 	char *  issuerNickName, 	PRFileDesc *inFile,	PRFileDesc *outFile, 	SECKEYPrivateKey *selfsignprivkey,	void 	*pwarg,	int     serialNumber, 	int     warpmonths,	int     validitylength,	PRBool  selfsign,	PRBool	keyUsage, 	PRBool  extKeyUsage,	PRBool  basicConstraint, 	PRBool  authKeyID,	PRBool  crlDistPoints, 	PRBool  nscpCertType){    void *	extHandle;    SECItem *	certDER;    PRArenaPool *arena			= NULL;    CERTCertificate *subjectCert 	= NULL;    /*CERTCertificate *issuerCert 	= NULL;*/    CERTCertificateRequest *certReq	= NULL;    SECStatus 	rv 			= SECSuccess;    SECItem 	reqDER;    reqDER.data = NULL;    do {	arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);	if (!arena) {	    GEN_BREAK (SEC_ERROR_NO_MEMORY);	}		/* Create a certrequest object from the input cert request der */	certReq = GetCertRequest(inFile);	if (certReq == NULL) {	    GEN_BREAK (SECFailure)	}	subjectCert = MakeV1Cert (handle, certReq, issuerNickName, selfsign,				  serialNumber, warpmonths, validitylength);	if (subjectCert == NULL) {	    GEN_BREAK (SECFailure)	}	extHandle = CERT_StartCertExtensions (subjectCert);	if (extHandle == NULL) {	    GEN_BREAK (SECFailure)	}	/* Add key usage extension */	if (keyUsage) {	    rv = AddKeyUsage(extHandle);	    if (rv)		break;	}	/* Add extended key usage extension */	if (extKeyUsage) {	    rv = AddExtKeyUsage(extHandle);	    if (rv)		break;	}	/* Add basic constraint extension */	if (basicConstraint) {	    rv = AddBasicConstraint(extHandle);	    if (rv)		break;	}	if (authKeyID) {	    rv = AddAuthKeyID (extHandle);	    if (rv)		break;	}    	if (crlDistPoints) {	    rv = AddCrlDistPoint (extHandle);	    if (rv)		break;	}		if (nscpCertType) {	    rv = AddNscpCertType(extHandle);	    if (rv)		break;	}       	CERT_FinishExtensions(extHandle);	certDER = SignCert (handle, subjectCert, selfsign, selfsignprivkey, issuerNickName,pwarg);	if (certDER)	   PR_Write(outFile, certDER->data, certDER->len);   	   /*fwrite (certDER->data, 1, certDER->len, outFile);*/    } while (0);    CERT_DestroyCertificateRequest (certReq);    CERT_DestroyCertificate (subjectCert);    PORT_FreeArena (arena, PR_FALSE);    if (rv != SECSuccess) {	PRErrorCode  perr = PR_GetError();        fprintf(stderr, "%s: unable to create cert (%s)\n", progName,               SECU_Strerror(perr));    }    return (rv);}