nameList = nssList_Create(NULL, PR_FALSE); (void)nssTrustDomain_GetCertsForNicknameFromCache(defaultTD, nickname, nameList);  search.callback = collect_certs; search.cbarg = nameList; search.cached = nameList; search.searchType = nssTokenSearchType_TokenOnly; nssrv = nssToken_TraverseCertificatesByNickname(token, NULL, nickname, &search); count = nssList_Count(nameList); foundCerts = nss_ZNEWARRAY(NULL, NSSCertificate *, count + 1); nssList_GetArray(nameList, (void **)foundCerts, count); nssList_Destroy(nameList);
if (!nssToken_SearchCerts(token)) { nameList = filter_token_certs_nickname(token, nickname); } else { nameList = nssList_Create(NULL, PR_FALSE); if (!nameList) return NULL; (void)nssTrustDomain_GetCertsForNicknameFromCache(defaultTD, nickname, nameList);  search.callback = collect_certs; search.cbarg = nameList; search.cached = nameList; search.searchType = nssTokenSearchType_TokenOnly; nssrv = nssToken_TraverseCertificatesByNickname(token, NULL, nickname, &search); } if (nameList) { count = nssList_Count(nameList); foundCerts = nss_ZNEWARRAY(NULL, NSSCertificate *, count + 1); nssList_GetArray(nameList, (void **)foundCerts, count); nssList_Destroy(nameList); }
PK11_FindCertsFromNickname(char *nickname, void *wincx) {#ifdef NSS_CLASSIC    PK11SlotInfo *slot;    int i,count = 0;    CK_OBJECT_HANDLE *certID = PK11_FindObjectsFromNickname(nickname,&slot,				 		CKO_CERTIFICATE, &count, wincx);    CERTCertList *certList = NULL;    if (certID == NULL) return NULL;    certList= CERT_NewCertList();    for (i=0; i < count; i++) {    	CERTCertificate *cert = PK11_MakeCertFromHandle(slot,certID[i],NULL);	if (cert) CERT_AddCertToListTail(certList,cert);    }    if (CERT_LIST_HEAD(certList) == NULL) {	CERT_DestroyCertList(certList);	certList = NULL;    }    PK11_FreeSlot(slot);    PORT_Free(certID);    return certList;#else    PRStatus nssrv;    char *delimit = NULL;    char *tokenName;    int i;    CERTCertList *certList = NULL;    NSSCertificate **foundCerts = NULL;    NSSTrustDomain *defaultTD = STAN_GetDefaultTrustDomain();    NSSCertificate *c;    NSSToken *token;    PK11SlotInfo *slot;    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;	PRUint32 count;	nssList *nameList;	if (!PK11_IsFriendly(slot)) {	    if (PK11_Authenticate(slot, PR_TRUE, wincx) != SECSuccess) {		PK11_FreeSlot(slot);		return NULL;	    }	}	nameList = nssList_Create(NULL, PR_FALSE);	(void)nssTrustDomain_GetCertsForNicknameFromCache(defaultTD,	                                                  nickname, 	                                                  nameList);	/* set the search criteria */	search.callback = collect_certs;	search.cbarg = nameList;	search.cached = nameList;	search.searchType = nssTokenSearchType_TokenOnly;	nssrv = nssToken_TraverseCertificatesByNickname(token, NULL, 	                                                nickname, &search);	count = nssList_Count(nameList);	foundCerts = nss_ZNEWARRAY(NULL, NSSCertificate *, count + 1);	nssList_GetArray(nameList, (void **)foundCerts, count);	nssList_Destroy(nameList);    }    if (slot) {	PK11_FreeSlot(slot);    }    if (foundCerts) {	certList = CERT_NewCertList();	for (i=0, c = *foundCerts; c; c = foundCerts[++i]) {	    CERT_AddCertToListTail(certList, STAN_GetCERTCertificate(c));	}	if (CERT_LIST_HEAD(certList) == NULL) {	    CERT_DestroyCertList(certList);	    certList = NULL;	}	nss_ZFreeIf(foundCerts);    }    return certList;#endif}