rv = SEC_ASN1DecodeItem(arena, lpk, keyTemplate, &pki->privateKey);
rv = SEC_QuickDERDecodeItem(arena, lpk, keyTemplate, &pki->privateKey);
pk11_unwrapPrivateKey(PK11Object *key, SECItem *bpki){    CK_BBOOL cktrue = CK_TRUE;     CK_KEY_TYPE keyType = CKK_RSA;    SECStatus rv = SECFailure;    const SEC_ASN1Template *keyTemplate, *paramTemplate;    void *paramDest = NULL;    PLArenaPool *arena;    NSSLOWKEYPrivateKey *lpk = NULL;    NSSLOWKEYPrivateKeyInfo *pki = NULL;    SECItem *ck_id = NULL;    CK_RV crv = CKR_KEY_TYPE_INCONSISTENT;    arena = PORT_NewArena(2048);    if(!arena) {	return SECFailure;    }    pki = (NSSLOWKEYPrivateKeyInfo*)PORT_ArenaZAlloc(arena, 					sizeof(NSSLOWKEYPrivateKeyInfo));    if(!pki) {	PORT_FreeArena(arena, PR_TRUE);	return SECFailure;    }    if(SEC_ASN1DecodeItem(arena, pki, nsslowkey_PrivateKeyInfoTemplate, bpki) 				!= SECSuccess) {	PORT_FreeArena(arena, PR_FALSE);	return SECFailure;    }    lpk = (NSSLOWKEYPrivateKey *)PORT_ArenaZAlloc(arena,						  sizeof(NSSLOWKEYPrivateKey));    if(lpk == NULL) {	goto loser;    }    lpk->arena = arena;    switch(SECOID_GetAlgorithmTag(&pki->algorithm)) {	case SEC_OID_PKCS1_RSA_ENCRYPTION:	    keyTemplate = nsslowkey_RSAPrivateKeyTemplate;	    paramTemplate = NULL;	    paramDest = NULL;	    lpk->keyType = NSSLOWKEYRSAKey;	    prepare_low_rsa_priv_key_for_asn1(lpk);	    break;	case SEC_OID_ANSIX9_DSA_SIGNATURE:	    keyTemplate = nsslowkey_DSAPrivateKeyExportTemplate;	    paramTemplate = nsslowkey_PQGParamsTemplate;	    paramDest = &(lpk->u.dsa.params);	    lpk->keyType = NSSLOWKEYDSAKey;	    prepare_low_dsa_priv_key_export_for_asn1(lpk);	    prepare_low_pqg_params_for_asn1(&lpk->u.dsa.params);	    break;	/* case NSSLOWKEYDHKey: */	default:	    keyTemplate = NULL;	    paramTemplate = NULL;	    paramDest = NULL;	    break;    }    if(!keyTemplate) {	goto loser;    }    /* decode the private key and any algorithm parameters */    rv = SEC_ASN1DecodeItem(arena, lpk, keyTemplate, &pki->privateKey);    if(rv != SECSuccess) {	goto loser;    }    if(paramDest && paramTemplate) {	rv = SEC_ASN1DecodeItem(arena, paramDest, paramTemplate, 				 &(pki->algorithm.parameters));	if(rv != SECSuccess) {	    goto loser;	}    }    rv = SECFailure;    switch (lpk->keyType) {        case NSSLOWKEYRSAKey:	    keyType = CKK_RSA;	    if(pk11_hasAttribute(key, CKA_NETSCAPE_DB)) {		pk11_DeleteAttributeType(key, CKA_NETSCAPE_DB);	    }	    crv = pk11_AddAttributeType(key, CKA_KEY_TYPE, &keyType, 					sizeof(keyType));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_UNWRAP, &cktrue, 					sizeof(CK_BBOOL));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_DECRYPT, &cktrue, 					sizeof(CK_BBOOL));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_SIGN, &cktrue, 					sizeof(CK_BBOOL));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_SIGN_RECOVER, &cktrue, 				    sizeof(CK_BBOOL));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_MODULUS, 				pk11_item_expand(&lpk->u.rsa.modulus));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_PUBLIC_EXPONENT, 	     			pk11_item_expand(&lpk->u.rsa.publicExponent));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_PRIVATE_EXPONENT, 	     			pk11_item_expand(&lpk->u.rsa.privateExponent));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_PRIME_1, 				pk11_item_expand(&lpk->u.rsa.prime1));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_PRIME_2, 	     			pk11_item_expand(&lpk->u.rsa.prime2));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_EXPONENT_1, 	     			pk11_item_expand(&lpk->u.rsa.exponent1));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_EXPONENT_2, 	     			pk11_item_expand(&lpk->u.rsa.exponent2));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_COEFFICIENT, 	     			pk11_item_expand(&lpk->u.rsa.coefficient));	    break;        case NSSLOWKEYDSAKey:	    keyType = CKK_DSA;	    crv = (pk11_hasAttribute(key, CKA_NETSCAPE_DB)) ? CKR_OK :						CKR_KEY_TYPE_INCONSISTENT;	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_KEY_TYPE, &keyType, 						sizeof(keyType));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_SIGN, &cktrue, 						sizeof(CK_BBOOL));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_SIGN_RECOVER, &cktrue, 						sizeof(CK_BBOOL)); 	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_PRIME,    				    pk11_item_expand(&lpk->u.dsa.params.prime));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_SUBPRIME,				 pk11_item_expand(&lpk->u.dsa.params.subPrime));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_BASE,  				    pk11_item_expand(&lpk->u.dsa.params.base));	    if(crv != CKR_OK) break;	    crv = pk11_AddAttributeType(key, CKA_VALUE, 			pk11_item_expand(&lpk->u.dsa.privateValue));	    if(crv != CKR_OK) break;	    break;#ifdef notdef        case NSSLOWKEYDHKey:	    template = dhTemplate;	    templateCount = sizeof(dhTemplate)/sizeof(CK_ATTRIBUTE);	    keyType = CKK_DH;	    break;#endif	/* what about fortezza??? */	default:	    crv = CKR_KEY_TYPE_INCONSISTENT;	    break;    }loser:    if(ck_id) {	SECITEM_ZfreeItem(ck_id, PR_TRUE);    }    if(lpk) {	nsslowkey_DestroyPrivateKey(lpk);    }    if(crv != CKR_OK) {	return SECFailure;    }    return SECSuccess;}