libopensc: Removes useless attribute 'file' in 'struct sc_pkcs15_df'

There is no need to carry around that attribute, because it's easy to look up the 'file' as needed. This is done by issuing a single sc_select_file command in sc_pkcs15init_update_any_df (pkcs15-lib.c).

The parameter 'file' of sc_pkcs15_add_df (pkcs15.c) became useless too and was removed in turn.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5316 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
andre 2011-04-10 04:09:33 +00:00
parent 86af8eed3d
commit 3169f14b32
6 changed files with 15 additions and 32 deletions

View File

@ -372,7 +372,7 @@ sc_pkcs15emu_get_df(sc_pkcs15_card_t *p15card, unsigned int type)
if (!file)
return NULL;
sc_format_path("11001101", &file->path);
sc_pkcs15_add_df(p15card, type, &file->path, file);
sc_pkcs15_add_df(p15card, type, &file->path);
sc_file_free(file);
created++;
}

View File

@ -502,7 +502,7 @@ sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "postpone adding of the private keys");
sc_format_path("5011A5A5", &path);
rv = sc_pkcs15_add_df(p15card, SC_PKCS15_PRKDF, &path, NULL);
rv = sc_pkcs15_add_df(p15card, SC_PKCS15_PRKDF, &path);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Add PrkDF error");
no_more_private_keys = 1;
}
@ -521,7 +521,7 @@ sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "postpone adding of the private data");
sc_format_path("5011A6A6", &path);
rv = sc_pkcs15_add_df(p15card, SC_PKCS15_DODF, &path, NULL);
rv = sc_pkcs15_add_df(p15card, SC_PKCS15_DODF, &path);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Add DODF error");
no_more_private_data = 1;
}

View File

@ -317,7 +317,7 @@ static sc_pkcs15_df_t * sc_pkcs15emu_get_df(sc_pkcs15_card_t *p15card,
if (!file)
return NULL;
sc_format_path("11001101", &file->path);
sc_pkcs15_add_df(p15card, type, &file->path, file);
sc_pkcs15_add_df(p15card, type, &file->path);
sc_file_free(file);
created++;
}

View File

@ -457,7 +457,7 @@ static int parse_odf(const u8 * buf, size_t buflen, struct sc_pkcs15_card *p15ca
r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &path);
if (r < 0)
return r;
r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path, NULL);
r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
if (r)
return r;
}
@ -1482,9 +1482,7 @@ void sc_pkcs15_free_object(struct sc_pkcs15_object *obj)
free(obj);
}
int sc_pkcs15_add_df(struct sc_pkcs15_card *p15card,
unsigned int type, const sc_path_t *path,
const sc_file_t *file)
int sc_pkcs15_add_df(struct sc_pkcs15_card *p15card, unsigned int type, const sc_path_t *path)
{
struct sc_pkcs15_df *p, *newdf;
@ -1493,14 +1491,6 @@ int sc_pkcs15_add_df(struct sc_pkcs15_card *p15card,
return SC_ERROR_OUT_OF_MEMORY;
newdf->path = *path;
newdf->type = type;
if (file != NULL) {
sc_file_dup(&newdf->file, file);
if (newdf->file == NULL) {
free(newdf);
return SC_ERROR_OUT_OF_MEMORY;
}
}
if (p15card->df_list == NULL) {
p15card->df_list = newdf;
@ -1525,8 +1515,6 @@ void sc_pkcs15_remove_df(struct sc_pkcs15_card *p15card,
obj->prev->next = obj->next;
if (obj->next != NULL)
obj->next->prev = obj->prev;
if (obj->file)
sc_file_free(obj->file);
free(obj);
}
@ -1635,10 +1623,7 @@ int sc_pkcs15_parse_df(struct sc_pkcs15_card *p15card,
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "unknown DF type: %d", df->type);
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS);
}
if (df->file != NULL)
r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, NULL);
else
r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, &df->file);
r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, NULL);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "pkcs15 read file failed");
p = buf;

View File

@ -418,8 +418,6 @@ typedef struct sc_pkcs15_object sc_pkcs15_object_t;
struct sc_pkcs15_card;
struct sc_pkcs15_df {
struct sc_file *file;
struct sc_path path;
int record_length;
unsigned int type;
@ -724,8 +722,7 @@ int sc_pkcs15_add_object(struct sc_pkcs15_card *p15card,
struct sc_pkcs15_object *obj);
void sc_pkcs15_remove_object(struct sc_pkcs15_card *p15card,
struct sc_pkcs15_object *obj);
int sc_pkcs15_add_df(struct sc_pkcs15_card *, unsigned int,
const sc_path_t *, const struct sc_file *);
int sc_pkcs15_add_df(struct sc_pkcs15_card *, unsigned int, const sc_path_t *);
void sc_pkcs15_remove_df(struct sc_pkcs15_card *p15card,
struct sc_pkcs15_df *df);

View File

@ -2494,14 +2494,15 @@ sc_pkcs15init_update_any_df(struct sc_pkcs15_card *p15card,
{
struct sc_context *ctx = p15card->card->ctx;
struct sc_card *card = p15card->card;
struct sc_file *file = df->file, *pfile = NULL;
struct sc_file *file = NULL;
unsigned char *buf = NULL;
size_t bufsize;
int update_odf = is_new, r = 0;
LOG_FUNC_CALLED(ctx);
if (!sc_profile_get_file_by_path(profile, &df->path, &pfile))
file = pfile;
sc_profile_get_file_by_path(profile, &df->path, &file);
if (file == NULL)
sc_select_file(card, &df->path, &file);
r = sc_pkcs15_encode_df(card->ctx, p15card, df, &buf, &bufsize);
if (r >= 0) {
@ -2523,8 +2524,8 @@ sc_pkcs15init_update_any_df(struct sc_pkcs15_card *p15card,
}
free(buf);
}
if (pfile)
sc_file_free(pfile);
if (file)
sc_file_free(file);
LOG_TEST_RET(ctx, r, "Failed to encode or update xDF");
@ -2560,7 +2561,7 @@ sc_pkcs15init_add_object(struct sc_pkcs15_card *p15card,
sc_log(ctx, "Profile doesn't define a DF file %u", df_type);
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "DF not found in profile");
}
sc_pkcs15_add_df(p15card, df_type, &file->path, file);
sc_pkcs15_add_df(p15card, df_type, &file->path);
df = find_df_by_type(p15card, df_type);
assert(df != NULL);
is_new = 1;