case rsaKey:
case lowRSAKey:
pk11_importPublicKey(PK11Slot *slot,	SECKEYLowPrivateKey *lowPriv, CERTCertificate *cert, SECItem *dbKey){    PK11Object *publicKey = NULL;    CK_KEY_TYPE key_type;    CK_BBOOL cktrue = CK_TRUE;    CK_BBOOL ckfalse = CK_FALSE;    CK_BBOOL verify = CK_TRUE;    CK_BBOOL recover = CK_TRUE;    CK_BBOOL encrypt = CK_TRUE;    CK_BBOOL derive = CK_FALSE;    CK_RV crv = CKR_OK;    CK_OBJECT_CLASS pubClass = CKO_PUBLIC_KEY;    unsigned char cka_id[SHA1_LENGTH];    KeyType keyType = nullKey;    SECKEYPublicKey *pubKey = NULL;    CK_ATTRIBUTE theTemplate[2];    PK11ObjectListElement *objectList = NULL;    if (lowPriv == NULL) {	pubKey = CERT_ExtractPublicKey(cert);	if (pubKey == NULL) {	    goto failed;	}	/* pk11_GetPubItem returns data associated with the public key.	 * one only needs to free the public key. This comment is here	 * because this sematic would be non-obvious otherwise. All callers	 * should include this comment.	 */	dbKey = pk11_GetPubItem(pubKey);	if (dbKey == NULL) {	    goto failed;	}    }    SHA1_HashBuf(cka_id, (unsigned char *)dbKey->data, (uint32)dbKey->len);    theTemplate[0].type = CKA_ID;    theTemplate[0].pValue = cka_id;    theTemplate[0].ulValueLen = sizeof(cka_id);    theTemplate[1].type = CKA_CLASS;    theTemplate[1].pValue = &pubClass;    theTemplate[1].ulValueLen = sizeof(CK_OBJECT_CLASS);    crv = pk11_searchObjectList(&objectList,slot->tokObjects,		slot->objectLock, theTemplate, 2, slot->isLoggedIn);    if ((crv == CKR_OK) && (objectList != NULL)) {	goto failed;    }    /*     * now lets create an object to hang the attributes off of     */    publicKey = pk11_NewObject(slot); /* fill in the handle later */    if (publicKey == NULL) {	goto failed;    }    /* now force the CKA_ID */    if (pk11_AddAttributeType(publicKey, CKA_ID, cka_id, sizeof(cka_id))) {	goto failed;    }    /* Fill in the common Default values */    if (pk11_AddAttributeType(publicKey,CKA_CLASS,&pubClass,					sizeof(CK_OBJECT_CLASS)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_TOKEN, &cktrue,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_PRIVATE, &ckfalse,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_MODIFIABLE, &cktrue,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_LABEL, NULL, 0) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_START_DATE, NULL, 0) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_END_DATE, NULL, 0) != CKR_OK) {	goto failed;    }    /* local: well we really don't know for sure... it could have been an      * imported key, but it's not a useful attribute anyway. */    if (pk11_AddAttributeType(publicKey,CKA_LOCAL, &cktrue,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_SUBJECT, NULL, 0) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_SENSITIVE, &ckfalse,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_EXTRACTABLE, &cktrue,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_ALWAYS_SENSITIVE, &ckfalse,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_NEVER_EXTRACTABLE, &ckfalse,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    /* Now Set up the parameters to generate the key (based on mechanism) */    if (lowPriv == NULL) {	keyType = pubKey->keyType;    } else {	keyType = lowPriv->keyType;    }     switch (keyType) {    case rsaKey:	/* format the keys */	key_type = CKK_RSA;	verify = CK_TRUE;	recover = CK_TRUE;	encrypt = CK_TRUE;	derive = CK_FALSE;        /* now fill in the RSA dependent parameters in the public key */ 	if (lowPriv) {            crv = pk11_AddAttributeType(publicKey,CKA_MODULUS,			   pk11_item_expand(&lowPriv->u.rsa.modulus));	    if (crv != CKR_OK) break;            crv = pk11_AddAttributeType(publicKey,CKA_PUBLIC_EXPONENT,			   pk11_item_expand(&lowPriv->u.rsa.publicExponent));	    if (crv != CKR_OK) break;	} else {            crv = pk11_AddAttributeType(publicKey,CKA_MODULUS,			   pk11_item_expand(&pubKey->u.rsa.modulus));	    if (crv != CKR_OK) break;            crv = pk11_AddAttributeType(publicKey,CKA_PUBLIC_EXPONENT,			   pk11_item_expand(&pubKey->u.rsa.publicExponent));	    if (crv != CKR_OK) break;	}	break;    case dsaKey:	key_type = CKK_DSA;	verify = CK_TRUE;	recover = CK_FALSE;	encrypt = CK_FALSE;	derive = CK_FALSE; 	if (lowPriv) {	    crv = pk11_AddAttributeType(publicKey,CKA_PRIME,			   pk11_item_expand(&lowPriv->u.dsa.params.prime));	    if (crv != CKR_OK) break;	    crv = pk11_AddAttributeType(publicKey,CKA_SUBPRIME,			   pk11_item_expand(&lowPriv->u.dsa.params.subPrime));	    if (crv != CKR_OK) break;	    crv = pk11_AddAttributeType(publicKey,CKA_BASE,			   pk11_item_expand(&lowPriv->u.dsa.params.base));	    if (crv != CKR_OK) break;	    crv = pk11_AddAttributeType(publicKey,CKA_VALUE,			   pk11_item_expand(&lowPriv->u.dsa.publicValue));	    if (crv != CKR_OK) break;	} else {	    crv = pk11_AddAttributeType(publicKey,CKA_PRIME,			   pk11_item_expand(&pubKey->u.dsa.params.prime));	    if (crv != CKR_OK) break;	    crv = pk11_AddAttributeType(publicKey,CKA_SUBPRIME,			   pk11_item_expand(&pubKey->u.dsa.params.subPrime));	    if (crv != CKR_OK) break;	    crv = pk11_AddAttributeType(publicKey,CKA_BASE,			   pk11_item_expand(&pubKey->u.dsa.params.base));	    if (crv != CKR_OK) break;	    crv = pk11_AddAttributeType(publicKey,CKA_VALUE,			   pk11_item_expand(&pubKey->u.dsa.publicValue));	    if (crv != CKR_OK) break;	}	break;    case dhKey:	key_type = CKK_DH;	verify = CK_FALSE;	encrypt = CK_FALSE;	recover = CK_FALSE;	derive = CK_TRUE;	crv = CKR_MECHANISM_INVALID;	break;    default:	crv = CKR_MECHANISM_INVALID;    }    if (pubKey) {	SECKEY_DestroyPublicKey(pubKey);	pubKey = NULL;    }    if (crv != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_VERIFY, &verify,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_VERIFY_RECOVER, &recover,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_ENCRYPT, &encrypt,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_WRAP, &encrypt,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_DERIVE, &derive,					      sizeof(CK_BBOOL)) != CKR_OK) {	goto failed;    }    if (pk11_AddAttributeType(publicKey,CKA_KEY_TYPE,&key_type,					     sizeof(CK_KEY_TYPE)) != CKR_OK) {	goto failed;    }    PK11_USE_THREADS(PZ_Lock(slot->objectLock);)    publicKey->handle = slot->tokenIDCount++;    publicKey->handle |= (PK11_TOKEN_MAGIC | PK11_TOKEN_TYPE_PUB);    PK11_USE_THREADS(PZ_Unlock(slot->objectLock);)    publicKey->objclass = pubClass;    publicKey->slot = slot;    publicKey->inDB = PR_FALSE; /* not really in the Database */    return publicKey;failed:    if (pubKey) SECKEY_DestroyPublicKey(pubKey);    if (publicKey) pk11_FreeObject(publicKey);    return NULL;}