PK11_SETATTRS(attrs,CKA_NETSCAPE_TRUST, certUsage, sizeof(SECCertUsage)); } else { certCount--;
PK11_SETATTRS(attrs,CKA_NETSCAPE_TRUST, certUsage, sizeof(SECCertUsage)); attrs++;
PK11_ImportCert(PK11SlotInfo *slot, CERTCertificate *cert, 		CK_OBJECT_HANDLE key, char *nickname, PRBool includeTrust) {    int len = 0;    SECItem *keyID = pk11_mkcertKeyID(cert);    CK_ATTRIBUTE keyAttrs[] = {	{ CKA_LABEL, NULL, 0},	{ CKA_SUBJECT, NULL, 0},    };    CK_OBJECT_CLASS certc = CKO_CERTIFICATE;    CK_CERTIFICATE_TYPE certType = CKC_X_509;    CK_OBJECT_HANDLE certID;    CK_SESSION_HANDLE rwsession;    CK_BBOOL cktrue = CK_TRUE;    SECStatus rv = SECFailure;    CK_ATTRIBUTE certAttrs[] = {	{ CKA_ID, NULL, 0 },	{ CKA_LABEL, NULL, 0},	{ CKA_CLASS,  NULL, 0},	{ CKA_TOKEN,  NULL, 0},	{ CKA_CERTIFICATE_TYPE, NULL, 0},	{ CKA_SUBJECT, NULL, 0},	{ CKA_ISSUER, NULL, 0},	{ CKA_SERIAL_NUMBER,  NULL, 0},	{ CKA_VALUE,  NULL, 0},	{ CKA_NETSCAPE_TRUST,  NULL, 0},    };    int certCount = sizeof(certAttrs)/sizeof(certAttrs[0]), keyCount = 2;    CK_ATTRIBUTE *attrs;    CK_RV crv;    SECCertUsage *certUsage = NULL;    if (keyID == NULL) {	PORT_SetError(SEC_ERROR_ADDING_CERT);	return rv;    }    len = ((nickname) ? PORT_Strlen(nickname) : 0);        attrs = certAttrs;    PK11_SETATTRS(attrs,CKA_ID, keyID->data, keyID->len); attrs++;    if(nickname) {	PK11_SETATTRS(attrs,CKA_LABEL, nickname, len ); attrs++;    }    PK11_SETATTRS(attrs,CKA_CLASS, &certc, sizeof(certc) ); attrs++;    PK11_SETATTRS(attrs,CKA_TOKEN, &cktrue, sizeof(cktrue) ); attrs++;    PK11_SETATTRS(attrs,CKA_CERTIFICATE_TYPE, &certType,						sizeof(certType)); attrs++;    PK11_SETATTRS(attrs,CKA_SUBJECT, cert->derSubject.data,					 cert->derSubject.len ); attrs++;    PK11_SETATTRS(attrs,CKA_ISSUER, cert->derIssuer.data,					 cert->derIssuer.len ); attrs++;    PK11_SETATTRS(attrs,CKA_SERIAL_NUMBER, cert->serialNumber.data,					 cert->serialNumber.len); attrs++;    PK11_SETATTRS(attrs,CKA_VALUE, cert->derCert.data, cert->derCert.len);    if(includeTrust && PK11_IsInternal(slot)) {	attrs++;	certUsage = (SECCertUsage*)PORT_Alloc(sizeof(SECCertUsage));	if(!certUsage) {	    SECITEM_FreeItem(keyID,PR_TRUE);	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    return rv;	}	*certUsage = certUsageUserCertImport;	PK11_SETATTRS(attrs,CKA_NETSCAPE_TRUST, certUsage, sizeof(SECCertUsage));    } else {	certCount--;    }    attrs = keyAttrs;    if(nickname) {	PK11_SETATTRS(attrs,CKA_LABEL, nickname, len ); attrs++;    }    PK11_SETATTRS(attrs,CKA_SUBJECT, cert->derSubject.data,					 cert->derSubject.len );    if(!nickname) {	certCount--;	keyCount--;    }    rwsession = PK11_GetRWSession(slot);    if (key != CK_INVALID_HANDLE) {	crv = PK11_GETTAB(slot)->C_SetAttributeValue(rwsession,key,keyAttrs,								keyCount);	if (crv != CKR_OK) {	    PORT_SetError( PK11_MapError(crv) );	    goto done;	}    }    crv = PK11_GETTAB(slot)->			C_CreateObject(rwsession,certAttrs,certCount,&certID);    if (crv == CKR_OK) {	rv = SECSuccess;    } else {	PORT_SetError( PK11_MapError(crv) );    }    if (cert->slot == NULL) {	cert->slot = PK11_ReferenceSlot(slot);	if (cert->nssCertificate) {	    cert->nssCertificate->token = slot->nssToken;	} else {	    cert->nssCertificate = STAN_GetNSSCertificate(cert);	}    }done:    SECITEM_FreeItem(keyID,PR_TRUE);    PK11_RestoreROSession(slot,rwsession);    if(certUsage) {	PORT_Free(certUsage);    }    return rv;}