if (!cc) { return NULL; }
__CERT_NewTempCertificate(CERTCertDBHandle *handle, SECItem *derCert,			  char *nickname, PRBool isperm, PRBool copyDER){    PRStatus nssrv;    NSSCertificate *c;    CERTCertificate *cc;    NSSCertificate *tempCert;    nssPKIObject *pkio;    NSSCryptoContext *gCC = STAN_GetDefaultCryptoContext();    NSSTrustDomain *gTD = STAN_GetDefaultTrustDomain();    if (!isperm) {	NSSDER encoding;	NSSITEM_FROM_SECITEM(&encoding, derCert);	/* First, see if it is already a temp cert */	c = NSSCryptoContext_FindCertificateByEncodedCertificate(gCC, 	                                                       &encoding);	if (!c) {	    /* Then, see if it is already a perm cert */	    c = NSSTrustDomain_FindCertificateByEncodedCertificate(handle, 	                                                           &encoding);	}	if (c) {	    return STAN_GetCERTCertificate(c);	}    }    pkio = nssPKIObject_Create(NULL, NULL, gTD, gCC);    if (!pkio) {	return NULL;    }    c = nss_ZNEW(pkio->arena, NSSCertificate);    if (!c) {	nssPKIObject_Destroy(pkio);	return NULL;    }    c->object = *pkio;    if (copyDER) {	nssItem_Create(c->object.arena, &c->encoding, 	               derCert->len, derCert->data);    } else {	NSSITEM_FROM_SECITEM(&c->encoding, derCert);    }    /* Forces a decoding of the cert in order to obtain the parts used     * below     */    cc = STAN_GetCERTCertificate(c);    nssItem_Create(c->object.arena,                    &c->issuer, cc->derIssuer.len, cc->derIssuer.data);    nssItem_Create(c->object.arena,                    &c->subject, cc->derSubject.len, cc->derSubject.data);    if (PR_TRUE) {	/* CERTCertificate stores serial numbers decoded.  I need the DER	* here.  sigh.	*/	SECItem derSerial = { 0 };	CERT_SerialNumberFromDERCert(&cc->derCert, &derSerial);	if (!derSerial.data) goto loser;	nssItem_Create(c->object.arena, &c->serial, derSerial.len, derSerial.data);	PORT_Free(derSerial.data);    }    if (nickname) {	c->object.tempName = nssUTF8_Create(c->object.arena,                                             nssStringType_UTF8String,                                             (NSSUTF8 *)nickname,                                             PORT_Strlen(nickname));    }    if (cc->emailAddr) {	c->email = nssUTF8_Create(c->object.arena, 	                          nssStringType_PrintableString, 	                          (NSSUTF8 *)cc->emailAddr, 	                          PORT_Strlen(cc->emailAddr));    }    /* this function cannot detect if the cert exists as a temp cert now, but     * didn't when CERT_NewTemp was first called.     */    nssrv = NSSCryptoContext_ImportCertificate(gCC, c);    if (nssrv != PR_SUCCESS) {	goto loser;    }    /* so find the entry in the temp store */    tempCert = NSSCryptoContext_FindCertificateByIssuerAndSerialNumber(gCC,                                                                   &c->issuer,                                                                   &c->serial);    /* destroy the copy */    NSSCertificate_Destroy(c);    if (tempCert) {	/* and use the "official" entry */	c = tempCert;	cc = STAN_GetCERTCertificate(c);    } else {	return NULL;    }    cc->istemp = PR_TRUE;    cc->isperm = PR_FALSE;    return cc;loser:    nssPKIObject_Destroy(&c->object);    return NULL;}