copyk->pkcs11Slot = NULL;	 copyk->pkcs11ID = CK_INVALID_HANDLE;
if (pubk->pkcs11Slot && PK11_IsPermObject(pubk->pkcs11Slot,pubk->pkcs11ID)) { copyk->pkcs11Slot = PK11_ReferenceSlot(pubk->pkcs11Slot); copyk->pkcs11ID = pubk->pkcs11ID; } else { copyk->pkcs11Slot = NULL;	 copyk->pkcs11ID = CK_INVALID_HANDLE; }
SECKEY_CopyPublicKey(SECKEYPublicKey *pubk){    SECKEYPublicKey *copyk;    PRArenaPool *arena;        arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);    if (arena == NULL) {	PORT_SetError (SEC_ERROR_NO_MEMORY);	return NULL;    }    copyk = (SECKEYPublicKey *) PORT_ArenaZAlloc (arena, sizeof (SECKEYPublicKey));    if (copyk != NULL) {	SECStatus rv = SECSuccess;	copyk->arena = arena;	copyk->keyType = pubk->keyType;	copyk->pkcs11Slot = NULL;	/* go get own reference */	copyk->pkcs11ID = CK_INVALID_HANDLE;	switch (pubk->keyType) {	  case rsaKey:	    rv = SECITEM_CopyItem(arena, &copyk->u.rsa.modulus,				  &pubk->u.rsa.modulus);	    if (rv == SECSuccess) {		rv = SECITEM_CopyItem (arena, &copyk->u.rsa.publicExponent,				       &pubk->u.rsa.publicExponent);		if (rv == SECSuccess)		    return copyk;	    }	    break;	  case dsaKey:	    rv = SECITEM_CopyItem(arena, &copyk->u.dsa.publicValue,				  &pubk->u.dsa.publicValue);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.dsa.params.prime,				  &pubk->u.dsa.params.prime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.dsa.params.subPrime,				  &pubk->u.dsa.params.subPrime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.dsa.params.base,				  &pubk->u.dsa.params.base);	    break;          case keaKey:            rv = SECITEM_CopyItem(arena, &copyk->u.kea.publicValue,                                  &pubk->u.kea.publicValue);            if (rv != SECSuccess) break;            rv = SECITEM_CopyItem(arena, &copyk->u.kea.params.hash,                                  &pubk->u.kea.params.hash);            break;	  case fortezzaKey:	    copyk->u.fortezza.KEAversion = pubk->u.fortezza.KEAversion;	    copyk->u.fortezza.DSSversion = pubk->u.fortezza.DSSversion;	    PORT_Memcpy(copyk->u.fortezza.KMID, pubk->u.fortezza.KMID,			sizeof(pubk->u.fortezza.KMID));	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.clearance, 				  &pubk->u.fortezza.clearance);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.KEApriviledge, 				&pubk->u.fortezza.KEApriviledge);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.DSSpriviledge, 				&pubk->u.fortezza.DSSpriviledge);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.KEAKey, 				&pubk->u.fortezza.KEAKey);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.DSSKey, 				&pubk->u.fortezza.DSSKey);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.params.prime, 				  &pubk->u.fortezza.params.prime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.params.subPrime, 				&pubk->u.fortezza.params.subPrime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.params.base, 				&pubk->u.fortezza.params.base);            if (rv != SECSuccess) break;            rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.keaParams.prime, 				  &pubk->u.fortezza.keaParams.prime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.keaParams.subPrime, 				&pubk->u.fortezza.keaParams.subPrime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.fortezza.keaParams.base, 				&pubk->u.fortezza.keaParams.base);	    break;	  case dhKey:            rv = SECITEM_CopyItem(arena,&copyk->u.dh.prime,&pubk->u.dh.prime);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena,&copyk->u.dh.base,&pubk->u.dh.base);	    if (rv != SECSuccess) break;	    rv = SECITEM_CopyItem(arena, &copyk->u.dh.publicValue, 				&pubk->u.dh.publicValue);	    break;	  case nullKey:	    return copyk;	  default:	    rv = SECFailure;	    break;	}	if (rv == SECSuccess)	    return copyk;	SECKEY_DestroyPublicKey (copyk);    } else {	PORT_SetError (SEC_ERROR_NO_MEMORY);    }    PORT_FreeArena (arena, PR_FALSE);    return NULL;}