Fix in new_file(): if there's already a key with such ID, take next one

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2522 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
sth 2005-08-26 19:35:33 +00:00
parent bb2506cff9
commit bae2b51e01
1 changed files with 10 additions and 0 deletions

View File

@ -288,6 +288,7 @@ setcos_new_file(sc_profile_t *profile, sc_card_t *card,
sc_file_t *file;
sc_path_t *p;
char name[64], *tag;
int r;
if (type == SC_PKCS15_TYPE_PRKEY_RSA)
tag = "private-key";
@ -316,6 +317,15 @@ setcos_new_file(sc_profile_t *profile, sc_card_t *card,
p->value[p->len++] = (u8) (file->id / 256);
p->value[p->len++] = (u8) (file->id % 256);
/* Increment FID until there's no file with such path */
r = sc_select_file(card, p, NULL);
while(r == 0) {
file->id++;
p->value[p->len - 2] = (u8) (file->id / 256);
p->value[p->len - 1] = (u8) (file->id % 256);
r = sc_select_file(card, p, NULL);
}
*out = file;
return 0;
}