libopensc: introduce TLV and LV data type, use it to store DDO data

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5051 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
vtarasov 2011-01-06 16:16:24 +00:00
parent b9e25370ab
commit 209224816a
5 changed files with 29 additions and 23 deletions

View File

@ -123,12 +123,6 @@
#define AUTHENTIC_GP_SM_LEVEL_MAC 0x4000
#define AUTHENTIC_GP_SM_LEVEL_ENC_MAC 0x6000
struct sc_authentic_tlv {
unsigned tag;
size_t size;
unsigned char *value;
};
/*
* DOCP (Data Object Control Parameters)
* Common holder for the all DOCP types.

View File

@ -110,16 +110,16 @@ static int parse_dir_record(sc_card_t *card, u8 ** buf, size_t *buflen,
} else
app->path.len = 0;
if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) {
app->ddo = malloc(ddo_len);
if (app->ddo == NULL) {
app->ddo.value = malloc(ddo_len);
if (app->ddo.value == NULL) {
free(app);
return SC_ERROR_OUT_OF_MEMORY;
}
memcpy(app->ddo, ddo, ddo_len);
app->ddo_len = ddo_len;
memcpy(app->ddo.value, ddo, ddo_len);
app->ddo.len = ddo_len;
} else {
app->ddo = NULL;
app->ddo_len = 0;
app->ddo.value = NULL;
app->ddo.len = 0;
}
app->rec_nr = rec_nr;
@ -235,8 +235,8 @@ void sc_free_apps(sc_card_t *card)
for (i = 0; i < card->app_count; i++) {
if (card->app[i]->label)
free(card->app[i]->label);
if (card->app[i]->ddo)
free(card->app[i]->ddo);
if (card->app[i]->ddo.value)
free(card->app[i]->ddo.value);
free(card->app[i]);
}
card->app_count = -1;
@ -261,9 +261,9 @@ static int encode_dir_record(sc_context_t *ctx, const sc_app_info_t *app,
if (tapp.path.len)
sc_format_asn1_entry(asn1_dirrecord + 2, (void *) tapp.path.value,
(void *) &tapp.path.len, 1);
if (tapp.ddo != NULL)
sc_format_asn1_entry(asn1_dirrecord + 3, (void *) tapp.ddo,
(void *) &tapp.ddo_len, 1);
if (tapp.ddo.value != NULL && tapp.ddo.len)
sc_format_asn1_entry(asn1_dirrecord + 3, (void *) tapp.ddo.value,
(void *) &tapp.ddo.len, 1);
r = sc_asn1_encode(ctx, asn1_dir, buf, buflen);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Encode DIR record error");

View File

@ -207,11 +207,12 @@ typedef struct sc_algorithm_info {
} sc_algorithm_info_t;
typedef struct sc_app_info {
struct sc_aid aid;
char *label;
struct sc_aid aid;
struct sc_lv_data ddo;
struct sc_path path;
u8 *ddo;
size_t ddo_len;
int rec_nr; /* -1, if EF(DIR) is transparent */
} sc_app_info_t;

View File

@ -703,8 +703,8 @@ static int sc_pkcs15_bind_internal(sc_pkcs15_card_t *p15card, struct sc_aid *aid
if (info->path.len)
p15card->file_app->path = info->path;
if (info->ddo)
parse_ddo(p15card, info->ddo, info->ddo_len);
if (info->ddo.value && info->ddo.len)
parse_ddo(p15card, info->ddo.value, info->ddo.len);
}
else if (aid) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Application(aid:'%s') not found", sc_dump_hex(aid->value, aid->len));

View File

@ -54,8 +54,19 @@ struct sc_object_id {
};
struct sc_aid {
unsigned char value[SC_MAX_AID_SIZE];
size_t len;
unsigned char value[SC_MAX_AID_SIZE];
};
struct sc_lv_data {
size_t len;
unsigned char *value;
};
struct sc_tlv_data {
unsigned tag;
size_t len;
unsigned char *value;
};
#define SC_PATH_TYPE_FILE_ID 0