case rsaKey:
case lowRSAKey:
seckey_encrypt_private_key(	SECKEYLowPrivateKey *pk, SECItem *pwitem, SECKEYKeyDBHandle *keydb,	SECOidTag algorithm){    SECKEYEncryptedPrivateKeyInfo *epki = NULL;    SECKEYPrivateKeyInfo *pki = NULL;    SECStatus rv = SECFailure;    SECAlgorithmID *algid = NULL;    PLArenaPool *temparena = NULL, *permarena = NULL;    SECItem *key = NULL, *salt = NULL, *der_item = NULL;    SECItem *dummy = NULL, *dest = NULL;    permarena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);    if(permarena == NULL)	return NULL;    temparena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);    if(temparena == NULL)	goto loser;    /* allocate structures */    epki = (SECKEYEncryptedPrivateKeyInfo *)PORT_ArenaZAlloc(permarena,	sizeof(SECKEYEncryptedPrivateKeyInfo));    pki = (SECKEYPrivateKeyInfo *)PORT_ArenaZAlloc(temparena, 	sizeof(SECKEYPrivateKeyInfo));    der_item = (SECItem *)PORT_ArenaZAlloc(temparena, sizeof(SECItem));    if((epki == NULL) || (pki == NULL) || (der_item == NULL))	goto loser;    epki->arena = permarena;    /* setup private key info */    dummy = SEC_ASN1EncodeInteger(temparena, &(pki->version), 	SEC_PRIVATE_KEY_INFO_VERSION);    if(dummy == NULL)	goto loser;    /* Encode the key, and set the algorithm (with params) */    switch (pk->keyType) {      case rsaKey:	dummy = SEC_ASN1EncodeItem(temparena, &(pki->privateKey), pk, 				   SECKEY_RSAPrivateKeyTemplate);	if (dummy == NULL) {	    rv = SECFailure;	    goto loser;	}		rv = SECOID_SetAlgorithmID(temparena, &(pki->algorithm), 				   SEC_OID_PKCS1_RSA_ENCRYPTION, 0);	if (rv == SECFailure) {	    goto loser;	}		break;      case dsaKey:	dummy = SEC_ASN1EncodeItem(temparena, &(pki->privateKey), pk,				   SECKEY_DSAPrivateKeyTemplate);	if (dummy == NULL) {	    rv = SECFailure;	    goto loser;	}		dummy = SEC_ASN1EncodeItem(temparena, NULL, &pk->u.dsa.params,				   SECKEY_PQGParamsTemplate);	if (dummy == NULL) {	    rv = SECFailure;	    goto loser;	}		rv = SECOID_SetAlgorithmID(temparena, &(pki->algorithm),				   SEC_OID_ANSIX9_DSA_SIGNATURE, dummy);	if (rv == SECFailure) {	    goto loser;	}		break;      case dhKey:	dummy = SEC_ASN1EncodeItem(temparena, &(pki->privateKey), pk,				   SECKEY_DHPrivateKeyTemplate);	if (dummy == NULL) {	    rv = SECFailure;	    goto loser;	}	rv = SECOID_SetAlgorithmID(temparena, &(pki->algorithm),				   SEC_OID_X942_DIFFIE_HELMAN_KEY, dummy);	if (rv == SECFailure) {	    goto loser;	}	break;      default:	/* We don't support DH or Fortezza private keys yet */	PORT_Assert(PR_FALSE);	break;    }    /* setup encrypted private key info */    dummy = SEC_ASN1EncodeItem(temparena, der_item, pki, 	SECKEY_PrivateKeyInfoTemplate);    if(dummy == NULL) {	rv = SECFailure;	goto loser;    }    rv = SECFailure; /* assume failure */    switch(algorithm)    {	case SEC_OID_RC4:	    salt = seckey_create_rc4_salt();	    if(salt != NULL)	    {		key = seckey_create_rc4_key(pwitem, salt);		if(key != NULL)		{		    dest = seckey_rc4_cipher(key, der_item, PR_TRUE);		    if(dest != NULL)		    {			rv = SECITEM_CopyItem(permarena, &epki->encryptedData,			    dest);			if(rv == SECSuccess)			rv = SECOID_SetAlgorithmID(permarena, 			&epki->algorithm, SEC_OID_RC4, salt);		    }		}	    }	    if(dest != NULL)		SECITEM_FreeItem(dest, PR_TRUE);	    if(key != NULL)		SECITEM_ZfreeItem(key, PR_TRUE);	    break;	default:	    algid = SEC_PKCS5CreateAlgorithmID(algorithm, NULL, 1);	    if(algid != NULL)	    {		dest = SEC_PKCS5CipherData(algid, pwitem, 		der_item, PR_TRUE, NULL);		if(dest != NULL)		{		    rv = SECITEM_CopyItem(permarena, &epki->encryptedData,			    dest);		    if(rv == SECSuccess)			rv = SECOID_CopyAlgorithmID(permarena, 			    &epki->algorithm, algid);		}	    }	    if(dest != NULL)		SECITEM_FreeItem(dest, PR_TRUE);	    if(algid != NULL)		SECOID_DestroyAlgorithmID(algid, PR_TRUE);	    break;    }    /* let success fall through */loser:    if(rv == SECFailure)    {	PORT_FreeArena(permarena, PR_TRUE);	    epki = NULL;    }    if(temparena != NULL)	PORT_FreeArena(temparena, PR_TRUE);	    if(salt != NULL)	SECITEM_FreeItem(salt, PR_TRUE);    return epki;}