certList = nssList_Create(NULL, PR_FALSE); (void)nssTrustDomain_GetCertsForEmailAddressFromCache(defaultTD,
if (!nssToken_SearchCerts(token)) { certList = filter_token_certs_email(token, nickname); if (certList) { nssCertificateList_DoCallback(certList, get_newest_cert, (void *)&cert); } } else { certList = nssList_Create(NULL, PR_FALSE); if (!certList) return NULL; (void)nssTrustDomain_GetCertsForEmailAddressFromCache( defaultTD,
PK11_FindCertFromNickname(char *nickname, void *wincx) {#ifdef NSS_CLASSIC    PK11SlotInfo *slot;    int count=0;    CK_OBJECT_HANDLE *certID = PK11_FindObjectsFromNickname(nickname,&slot,				 		CKO_CERTIFICATE, &count, wincx);    CERTCertificate *cert;    if (certID == CK_INVALID_HANDLE) return NULL;    cert = PK11_MakeCertFromHandle(slot,certID[0],NULL);    PK11_FreeSlot(slot);    PORT_Free(certID);    return cert;#else    CERTCertificate *rvCert = NULL;    NSSCertificate *cert = NULL;    NSSUsage usage;    NSSToken *token;    PK11SlotInfo *slot = NULL;    char *delimit = NULL;    char *tokenName;    NSSTrustDomain *defaultTD = STAN_GetDefaultTrustDomain();    usage.anyUsage = PR_TRUE;    if ((delimit = PORT_Strchr(nickname,':')) != NULL) {	tokenName = nickname;	nickname = delimit + 1;	*delimit = '\0';	/* find token by name */	token = NSSTrustDomain_FindTokenByName(defaultTD, (NSSUTF8 *)tokenName);	slot = PK11_ReferenceSlot(token->pk11slot);	*delimit = ':';    } else {	slot = PK11_GetInternalKeySlot();	token = PK11Slot_GetNSSToken(slot);    }    if (token) {	nssTokenCertSearch search;	nssList *certList;	if (!PK11_IsFriendly(slot)) {	    if (PK11_Authenticate(slot, PR_TRUE, wincx) != SECSuccess) {		PK11_FreeSlot(slot);		return NULL;	    }	}	certList = nssList_Create(NULL, PR_FALSE);	(void)nssTrustDomain_GetCertsForNicknameFromCache(defaultTD, 	                                                  nickname, 	                                                  certList);	/* set the search criteria */	search.callback = get_newest_cert;	search.cbarg = (void *)&cert;	search.cached = certList;	search.searchType = nssTokenSearchType_TokenOnly;	/* find best cert on token */	nssToken_TraverseCertificatesByNickname(token, NULL, 	                                        (NSSUTF8 *)nickname,	                                        &search);	nssList_Clear(certList, cert_destructor);	nssList_Destroy(certList);	if (!cert) {	    certList = nssList_Create(NULL, PR_FALSE);	    (void)nssTrustDomain_GetCertsForEmailAddressFromCache(defaultTD, 	                                                          nickname, 	                                                          certList);	    search.cached = certList;	    nssToken_TraverseCertificatesByEmail(token, NULL, 	                                         (NSSASCII7 *)nickname,	                                         &search);	    nssList_Clear(certList, cert_destructor);	    nssList_Destroy(certList);	}	if (cert) {	    (void)nssTrustDomain_AddCertsToCache(defaultTD, &cert, 1);	    rvCert = STAN_GetCERTCertificate(cert);	}    }    if (slot) {	PK11_FreeSlot(slot);    }    return rvCert;#endif}