for (i=0; (ri = recipientArray[i]) != NULL; i++) { attrs = searchTemplate;  PK11_SETATTRS(attrs, CKA_CLASS, &certClass,sizeof(certClass)); attrs++; PK11_SETATTRS(attrs, CKA_ISSUER, ri->issuerAndSN->derIssuer.data, ri->issuerAndSN->derIssuer.len); attrs++; PK11_SETATTRS(attrs, CKA_SERIAL_NUMBER, ri->issuerAndSN->serialNumber.data,ri->issuerAndSN->serialNumber.len);  certHandle = pk11_FindObjectByTemplate(slot,searchTemplate,count); if (certHandle != CK_INVALID_HANDLE) { CERTCertificate *cert = pk11_fastCert(slot,certHandle,NULL,NULL); if (PK11_IsUserCert(slot,cert,certHandle)) {  *rip = ri;  CERT_DestroyCertificate(cert); return certHandle; } CERT_DestroyCertificate(cert); }
pk11_FindCertObjectByRecipient(PK11SlotInfo *slot, 	SEC_PKCS7RecipientInfo **recipientArray,SEC_PKCS7RecipientInfo **rip){    CK_OBJECT_HANDLE certHandle;    CK_OBJECT_CLASS certClass = CKO_CERTIFICATE;    CK_OBJECT_CLASS peerClass ;    CK_ATTRIBUTE searchTemplate[] = {	{ CKA_CLASS, NULL, 0 },	{ CKA_ISSUER, NULL, 0 },	{ CKA_SERIAL_NUMBER, NULL, 0}    };    int count = sizeof(searchTemplate)/sizeof(CK_ATTRIBUTE);    SEC_PKCS7RecipientInfo *ri = NULL;    CK_ATTRIBUTE *attrs;    int i;    peerClass = CKO_PRIVATE_KEY;    if (!PK11_IsLoggedIn(slot,NULL) && PK11_NeedLogin(slot)) {	peerClass = CKO_PUBLIC_KEY;    }    for (i=0; (ri = recipientArray[i]) != NULL; i++) {    	attrs = searchTemplate;	PK11_SETATTRS(attrs, CKA_CLASS, &certClass,sizeof(certClass)); attrs++;	PK11_SETATTRS(attrs, CKA_ISSUER, ri->issuerAndSN->derIssuer.data, 				ri->issuerAndSN->derIssuer.len); attrs++;	PK11_SETATTRS(attrs, CKA_SERIAL_NUMBER, 	  ri->issuerAndSN->serialNumber.data,ri->issuerAndSN->serialNumber.len);	certHandle = pk11_FindObjectByTemplate(slot,searchTemplate,count);	if (certHandle != CK_INVALID_HANDLE) {	    CERTCertificate *cert = pk11_fastCert(slot,certHandle,NULL,NULL);	    if (PK11_IsUserCert(slot,cert,certHandle)) {		/* we've found a cert handle, now let's see if there is a key	         * associated with it... */		*rip = ri;			CERT_DestroyCertificate(cert);       		return certHandle;	    }	    CERT_DestroyCertificate(cert);       	}    }    *rip = NULL;    return CK_INVALID_HANDLE;}