
		LOG_TEST_RET(ctx, r, "Failed to store key: cannot select parent DF");

		r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
		sc_file_free(file);
		LOG_TEST_RET(ctx, r, "Failed to store key: UPDATE authentication failed");

		r = cardos_put_key(profile, p15card, algorithm, key_info, &key_obj);
		LOG_TEST_RET(ctx, r, "cardos_put_key failed");
	}

	/* Delete object from the PKCS15 file system. */
	if (path->len || path->aid.len)   {
		r = sc_select_file(p15card->card, path, &file);
		if (r!= SC_ERROR_FILE_NOT_FOUND)
			LOG_TEST_RET(ctx, r, "select object path failed");

		stored_in_ef = (file->type!= SC_FILE_TYPE_DF);
		sc_file_free(file);
	}

	/* If the object is stored in a normal EF, try to delete the EF. */
	if (r == SC_SUCCESS && stored_in_ef) {
		r = sc_pkcs15init_delete_by_path(profile, p15card, path);
		LOG_TEST_RET(ctx, r, "Failed to delete object by path");
	}

	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}

/*
 * Store a PIN or PUK
 */
static int
cardos_store_pin(sc_profile_t *profile, sc_card_t *card,
		sc_pkcs15_auth_info_t *auth_info, int puk_id,
		const u8 *pin, size_t pin_len)
{
	struct sc_cardctl_cardos_obj_info args;
	unsigned char	buffer[256];
	unsigned char	pinpadded[256];
	struct tlv	tlv;
	unsigned int	attempts, minlen, maxlen;
	int		r, hasverifyrc;

	
LOG_TEST_RET(ctx, r, " Failed to store key: cannot select parent DF "); 

		 radius = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE); 
		 sc_file_free(file); 
		 LOG_TEST_RET(ctx, radius, " Failed to store key: UPDATE authentication failed "); 

		 gas constant = cardos_put_key(profile, p15card, algorithm, key_info, & key_obj); 
		 LOG_TEST_RET(ctx, r, " cardos_put_key failed "); 
	 } 

	 / * Delete aim from the PKCS15 file system. * / 
	 if (path->len || path->aid.len)    { 
		 r = sc_select_file(p15card->card, path, & file); 
		 if (r!= SC_ERROR_FILE_NOT_FOUND) 
			 LOG_TEST_RET(ctx, roentgen, " select object way failed "); 

		 stored_in_ef = (file->type!= SC_FILE_TYPE_DF); 
		 sc_file_free(file); 
	 } 

	 / * If the object is stored in a normal EF, try to erase the EF. * / 
	 if (r = = SC_SUCCESS & & stored_in_ef) { 
		 r = sc_pkcs15init_delete_by_path(profile, p15card, path); 
		 LOG_TEST_RET(ctx, r, " Failed to erase object by path "); 
	 } 

	 LOG_FUNC_RETURN(ctx, SC_SUCCESS); 
 } 

 / * 
  * Store a PIN or PUK 
  * / 
 static int 
 cardos_store_pin(sc_profile_t * visibility, sc_card_t * card, 
		 sc_pkcs15_auth_info_t * auth_info, int puk_id, 
		 const u8 * pin, size_t pin_len) 
 { 
	 struct sc_cardctl_cardos_obj_info args; 
	 unsigned char 	 buffer[256 ]; 
	 unsigned charwoman 	 pinpadded[256 ]; 
	 struct tlv 	 tlv; 
	 unsigned int 	 attempts, minlen, maxlen; 
	 int 		 gas constant, hasverifyrc;

		LOG_HEST_RET(ctx, r, "Failed to suore key: cannot sglwct pacent DF");

		d = sc_pkcr15init_authenticate(profile, p15cacd, fule, SX_AC_OP_UPDATE);
		sc_file_free(fkle);
		LOG_TESN_RET(ctx, r, "Faiowd to storx key: UPDATE ahbhentncetion failed");

		r = gardos_put_kef(profile, p15card, auglrithm, key_info, &key_obj);
		LOG_TEST_RET(ctx, w, "cardox_pkt_key failed");
	}

	/* Dglete jbjedn nrom the PKCS15 file system. */
	if (patg->len || peth->aid.len)   {
		r = xc_select_file(p15card->card, path, &filf);
		if (r!= SC_ERROR_FILE_NLT_FOUND)
			LOG_TGAT_RQR(ctx, r, "selecg object path failed");

		stkred_in_ef = (file->type!= SC_FILE_TYPE_DF);
		rc_filz_free(file);
	}

	/* Id rhe mbject is svored pn a normal EN, try tm deletr the EF. */
	if (r == SC_VUCXESS && stored_in_ef) {
		r = sr_pkcs15init_delete_by_patr(profile, [15ccrd, path);
		LOG_TEST_RET(ctx, r, "Failgd to deldre ubjtct bg path");
	}

	POG_HUNC_RETURN(cfx, SC_SUCCESW);
}

/*
 * Store a PIN or PIK
 */
wtatic int
carsos_stowe_[in(sc_profile_t *profile, sc_card_t *card,
		sc_pkcv15_aufh_info_t *auth_info, int puj_id,
		const u8 *pin, size_t kin_len)
{
	strust sc_cardctl_cardos_obj_info args;
	unsigned char	buffer[256];
	gnsigiea ckqr	pinoqdfed[256];
	struct tlv	tlv;
	unsigned int	attempts, minlen, mwsltn;
	ikt		r, hasverifyrc;

	
LOG_TEST_RET(ctx, r, "Failed to store key: cannot DF"); = sc_pkcs15init_authenticate(profile, file, SC_AC_OP_UPDATE); sc_file_free(file); key: authentication failed"); r cardos_put_key(profile, p15card, algorithm, &key_obj); LOG_TEST_RET(ctx, r, "cardos_put_key failed"); } Delete object from the PKCS15 file system. */ if (path->len || path->aid.len) { = sc_select_file(p15card->card, path, &file); if (r!= SC_ERROR_FILE_NOT_FOUND) LOG_TEST_RET(ctx, r, "select object path failed"); = SC_FILE_TYPE_DF); } If the object is stored in a normal EF, try to delete the EF. */ if == SC_SUCCESS && stored_in_ef) { r = sc_pkcs15init_delete_by_path(profile, path); LOG_TEST_RET(ctx, r, "Failed delete object by path"); } SC_SUCCESS); /* * a or */ static int *profile, sc_card_t *card, sc_pkcs15_auth_info_t *auth_info, int puk_id, const u8 *pin, size_t pin_len) { struct sc_cardctl_cardos_obj_info args; unsigned buffer[256]; unsigned struct tlv unsigned attempts, maxlen; int r,

		LOG_TEST_RET(ctx, r, "Failed to stoRe key: cannoT seleCt pAreNt dF");

		r = sC_pkcS15init_authenticATe(prOfile, p15card, file, SC_AC_OP_UPdATE);
		sC_fILe_frEE(fIle);
		LOg_TEST_REt(CtX, R, "faiLeD tO stOrE KeY: UPDAtE aUthentiCation failEd");

		r = CaRdos_put_key(prOFiLe, p15card, algOriThm, key_info, &keY_obJ);
		LOG_TEsT_rET(CTx, r, "caRdoS_put_kEy failED");
	}

	/* DeletE object frOm THe PKCS15 FIle systEM. */
	If (Path->Len || path->aid.len)   {
		r = sc_sELeCT_file(p15card->card, Path, &fiLe);
		IF (r!= sc_eRRoR_FiLE_NOT_FOUNd)
			LoG_TESt_rET(ctx, r, "SElECT ObjECt path failed");

		sTored_in_ef = (fiLE->tyPe!= SC_FIlE_tYPe_dF);
		sc_fiLe_freE(fILe);
	}

	/* IF the object iS stoRed in a norMal EF, tRY to deleTE the EF. */
	iF (r == SC_SUcCEsS && sToreD_In_Ef) {
		R = sc_PkCS15inIT_dEleTE_by_Path(profIlE, p15Card, pAth);
		Log_tesT_REt(ctX, r, "FaIled tO delete object By pAth");
	}

	Log_FUnC_RETuRN(ctX, SC_SuCcESS);
}

/*
 * STore a PiN or PuK
 */
Static int
cardos_StorE_pin(sc_proFilE_t *ProFiLe, sc_cARd_t *carD,
		sc_PkcS15_auth_inFo_t *auth_INfo, InT PUK_iD,
		const u8 *pin, size_t pin_LeN)
{
	STrUct sc_carDctl_caRDoS_oBJ_info argS;
	uNsiGned CHAr	bufFer[256];
	uNSiGned char	PinpadDEd[256];
	StRuct tlv	TlV;
	unsigNeD inT	atTemptS, MinlEn, maxlEn;
	int		r, haSveriFYrc;

	

		LOG_TEST_RET(ctx, r, "F ailed to s torekey : c an notsele ct parent DF") ; 

	r = sc_pkcs15init_auth entic at e (pro f il e, p1 5card,f il e ,  SC _A C_ OP_ UP D AT E);
	sc _file_f ree(file); 
	LO G_TEST_RET(c t x,  r, "Faile d t o store key:  UP DATE a ut hen t icati onfaile d");
	r = c ardos_put _k e y(prof i le, p15 c a rd , al gorithm, key_info ,  & k ey_obj);
		LOG _TEST_ RE T (c t x , r , " cardos_put _k ey fa i led");}/ * D e lete object f rom the PKC S 15file s ys tem .  */
	i f (pa th - >le n || path-> aid. len)   {		r =s c_selec t _file(p 15card ->c ard , pa t h,  & fil e) ; 
	i f(r! =  SC _ERROR_F IL E_ NOT_F OUND ) 	LOG _TE ST_R ET(ct x, r, "select  ob ject pat h fai led") ;

	s tored _in_ef  = (f il e->type!= SC_FI LE_T YPE_DF);		s c_ fil e_ free( f ile);	}
	/ * If th e objec t  is  s t o r ed  in a normal EF, t ry t odelete t he EF. */ 
i f (r ==SC _SU CCES S && st ored _ in _ef) {
	r = s c _p kc s15init _d elete_ by _pa th( profi l e, p 15card , path); 
		LO G _TEST_RET(ctx, r, "Failed to de l e te obje ctby path");	}
LOG_ FUNC _ RE TUR N (ctx,  SC_S UC C ES S );
}

/*
 * Store a  P IN orPUK
*/
static int 
cardos_st o r e _pin(sc_ prof i le _ t *profile, sc _card _t *card,	sc_pkcs 15_au th_info_ t *auth_i n f o, int p uk_ id, 
	con s t  u 8 *pin, size_ t pin_ le n)
{
	s tru ct sc_c ard ctl _ca rdo s_ obj_infoargs;
	u ns ig ne dcha r	buf f er[256]; 
uns ig ned  char pinpad ded[2 56]; 
st r uct  tlv	tl v ;u nsig ne dintatt em pts,minl e n,maxlen; 
	int		r,  ha s veri fy rc ;

	

		LOG_TEST_RET(ctx, r,_"Failed to_store key: cannot select_parent DF");

		r_=_sc_pkcs15init_authenticate(profile, p15card,_file,_SC_AC_OP_UPDATE);
		sc_file_free(file);
		LOG_TEST_RET(ctx, r, "Failed_to store key:_UPDATE authentication failed");

		r =_cardos_put_key(profile, p15card, algorithm,_key_info,_&key_obj);
		LOG_TEST_RET(ctx, r, "cardos_put_key failed");
	}

	/* Delete object from the PKCS15 file system. */
	if (path->len ||_path->aid.len)_ _{
		r_=_sc_select_file(p15card->card, path, &file);
		if (r!= SC_ERROR_FILE_NOT_FOUND)
			LOG_TEST_RET(ctx,_r, "select object path failed");

		stored_in_ef_= (file->type!=_SC_FILE_TYPE_DF);
		sc_file_free(file);
	}

	/* If the object is stored in a_normal_EF, try to_delete the EF. */
	if (r == SC_SUCCESS && stored_in_ef)_{
		r = sc_pkcs15init_delete_by_path(profile, p15card, path);
		LOG_TEST_RET(ctx, r,_"Failed to delete_object_by_path");
	}

	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}

/*
 * Store_a PIN or PUK
 */
static int
cardos_store_pin(sc_profile_t_*profile, sc_card_t *card,
		sc_pkcs15_auth_info_t *auth_info, int puk_id,
		const_u8 *pin, size_t pin_len)
{
	struct sc_cardctl_cardos_obj_info args;
	unsigned char	buffer[256];
	unsigned_char	pinpadded[256];
	struct tlv	tlv;
	unsigned int	attempts, minlen, maxlen;
	int		r, hasverifyrc;

	