On Tue, 2010-09-28 at 15:47 +0300, Martin Paljak wrote:
> Hello,
> On Sep 28, 2010, at 3:30 PM, Andre Zepezauer wrote:
> > personally I would like to keep this patch specific to the separation of
> > attributes from (public) TokenInfo and (internal) sc_pkcs15_card
> > structure. Fixing the use of tokeninfo->version is another task and
> > therefore I would suggest a separate patch for that one.
> Fine.
> 
> > The matter of renaming the flags related to TokenInfo sounds easy at
> > first. But trying to do it the right way has taken some time. Here is
> > what I found:
> > 
> > 1. Every data type directly related to PKCS#15 is prefixed with
> > sc_pkcs15. Upper case is used for constants.
> > 2. Every function operating on data types from 1) is prefixed with
> > sc_pkcs15 too.
> > 
> > 3. Two conventions are used for the naming of PKCS#15 flags:
> >   a) [SC_PKCS15] + [name of ASN1 type with last letter stripped] + [name of 
> > flag]
> >      (i.e. SC_PKCS15_PIN_FLAG_CASE_SENSITIVE)
> >   b) [SC_PKCS15] + [PR + name of ASN1 type with "FLAGS" stripped] + [name 
> > of flag]
> >      (i.e. SC_PKCS15_PRKEY_USAGE_ENCRYPT, SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE
> > 
> > 4. Everything dealing with card I/O has prefix of "sc" but not "sc_pkcs15"
> > 
> > Conclusion: For the new names of flags, I would prefer convention b) but 
> > without the misleading "PR" letters. For example SC_PKCS15_TOKEN_READONLY.
> Yes, that would make sense. 

Attached is the final patch. Naming of flags as mentioned above. All
changes were trivial with the exception of pkcs15init/pkcs15-oberthur.c

Kind Regards
Andre Zepezauer
Index: src/tools/pkcs15-crypt.c
===================================================================
--- src/tools/pkcs15-crypt.c	(revision 4779)
+++ src/tools/pkcs15-crypt.c	(working copy)
@@ -583,7 +583,7 @@
 		goto end;
 	}
 	if (verbose)
-		fprintf(stderr, "Found %s!\n", p15card->label);
+		fprintf(stderr, "Found %s!\n", p15card->tokeninfo->label);
 
 	if (do_decipher) {
 		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_DECRYPT, &key))
Index: src/tools/pkcs15-init.c
===================================================================
--- src/tools/pkcs15-init.c	(revision 4779)
+++ src/tools/pkcs15-init.c	(working copy)
@@ -462,7 +462,7 @@
 			 * sure we're not messing things up */
 
 			if (verbose)
-				printf("Found %s\n", p15card->label);
+				printf("Found %s\n", p15card->tokeninfo->label);
 
 			sc_pkcs15init_set_p15card(profile, p15card);
 
@@ -627,7 +627,7 @@
 
 	p15card = sc_pkcs15_card_new();
 	p15card->card = in_card;
-	p15card->label = strdup("Dummy PKCS#15 object");
+	p15card->tokeninfo->label = strdup("Dummy PKCS#15 object");
 
 	ignore_cmdline_pins++;
 	r = sc_pkcs15init_erase_card(p15card, profile);
Index: src/tools/pkcs15-tool.c
===================================================================
--- src/tools/pkcs15-tool.c	(revision 4779)
+++ src/tools/pkcs15-tool.c	(working copy)
@@ -1105,17 +1105,17 @@
 
 	int i, count = 0;
 
-	printf("PKCS#15 Card [%s]:\n", p15card->label);
-	printf("\tVersion        : %d\n", p15card->version);
-	printf("\tSerial number  : %s\n", p15card->serial_number);
-	printf("\tManufacturer ID: %s\n", p15card->manufacturer_id);
-	if (p15card->last_update)
-		printf("\tLast update    : %s\n", p15card->last_update);
-	if (p15card->preferred_language)
-		printf("\tLanguage       : %s\n", p15card->preferred_language);
+	printf("PKCS#15 Card [%s]:\n", p15card->tokeninfo->label);
+	printf("\tVersion        : %d\n", p15card->tokeninfo->version);
+	printf("\tSerial number  : %s\n", p15card->tokeninfo->serial_number);
+	printf("\tManufacturer ID: %s\n", p15card->tokeninfo->manufacturer_id);
+	if (p15card->tokeninfo->last_update)
+		printf("\tLast update    : %s\n", p15card->tokeninfo->last_update);
+	if (p15card->tokeninfo->preferred_language)
+		printf("\tLanguage       : %s\n", p15card->tokeninfo->preferred_language);
 	printf("\tFlags          : ");
 	for (i = 0; i < 4; i++) {
-		if ((p15card->flags >> i) & 1) {
+		if ((p15card->tokeninfo->flags >> i) & 1) {
 			if (count)
 				printf(", ");
 			printf("%s", flags[i]);
@@ -1731,7 +1731,7 @@
 	if (opt_no_cache)
 		p15card->opts.use_file_cache = 0;
 	if (verbose)
-		fprintf(stderr, "Found %s!\n", p15card->label);
+		fprintf(stderr, "Found %s!\n", p15card->tokeninfo->label);
 	
 	if (do_verify_pin)
 		if ((err = verify_pin()))
Index: src/pkcs11/framework-pkcs15.c
===================================================================
--- src/pkcs11/framework-pkcs15.c	(revision 4779)
+++ src/pkcs11/framework-pkcs15.c	(working copy)
@@ -192,7 +192,7 @@
 
 static void pkcs15_init_token_info(struct sc_pkcs15_card *p15card, CK_TOKEN_INFO_PTR pToken)
 {
-	strcpy_bp(pToken->manufacturerID, p15card->manufacturer_id, 32);
+	strcpy_bp(pToken->manufacturerID, p15card->tokeninfo->manufacturer_id, 32);
 	if (p15card->flags & SC_PKCS15_CARD_FLAG_EMULATED)
 		strcpy_bp(pToken->model, "PKCS#15 emulated", 16);
 	else
@@ -203,14 +203,12 @@
 	 * _Assuming_ that the serial number is a Big Endian counter, this
 	 * will assure that the serial within each type of card will be
 	 * unique in pkcs11 (at least for the first 8^16 cards :-) */
-	if (p15card->serial_number != NULL) {
-		int sn_start = strlen(p15card->serial_number) - 16;
+	if (p15card->tokeninfo->serial_number != NULL) {
+		int sn_start = strlen(p15card->tokeninfo->serial_number) - 16;
 
 		if (sn_start < 0)
 			sn_start = 0;
-		strcpy_bp(pToken->serialNumber,
-			p15card->serial_number + sn_start,
-			16);
+		strcpy_bp(pToken->serialNumber, p15card->tokeninfo->serial_number + sn_start, 16);
 	}
 
 	pToken->ulMaxSessionCount = CK_EFFECTIVELY_INFINITE;
@@ -791,13 +789,13 @@
 
 		if (auth->label[0]) {
 			snprintf(tmp, sizeof(tmp), "%s (%s)",
-				p15card->label, auth->label);
+				p15card->tokeninfo->label, auth->label);
 		} else {
-			snprintf(tmp, sizeof(tmp), "%s", p15card->label);
+			snprintf(tmp, sizeof(tmp), "%s", p15card->tokeninfo->label);
 		}
 		slot->token_info.flags |= CKF_LOGIN_REQUIRED;
 	} else
-		snprintf(tmp, sizeof(tmp), "%s", p15card->label);
+		snprintf(tmp, sizeof(tmp), "%s", p15card->tokeninfo->label);
 	strcpy_bp(slot->token_info.label, tmp, 32);
 
 	if (pin_info && pin_info->magic == SC_PKCS15_PIN_MAGIC) {
Index: src/tests/print.c
===================================================================
--- src/tests/print.c	(revision 4779)
+++ src/tests/print.c	(working copy)
@@ -25,15 +25,15 @@
 	int i, count = 0;
 
 	assert(mycard != NULL);
-	printf("PKCS#15 Card [%s]:\n", mycard->label);
-	printf("\tVersion        : %d\n", mycard->version);
-	printf("\tSerial number  : %s\n", mycard->serial_number);
-	printf("\tManufacturer ID: %s\n", mycard->manufacturer_id);
-	if (mycard->preferred_language)
-		printf("\tLanguage       : %s\n", mycard->preferred_language);
+	printf("PKCS#15 Card [%s]:\n", mycard->tokeninfo->label);
+	printf("\tVersion        : %d\n", mycard->tokeninfo->version);
+	printf("\tSerial number  : %s\n", mycard->tokeninfo->serial_number);
+	printf("\tManufacturer ID: %s\n", mycard->tokeninfo->manufacturer_id);
+	if (mycard->tokeninfo->preferred_language)
+		printf("\tLanguage       : %s\n", mycard->tokeninfo->preferred_language);
 	printf("\tFlags          : ");
 	for (i = 0; i < 4; i++) {
-		if ((mycard->flags >> i) & 1) {
+		if ((mycard->tokeninfo->flags >> i) & 1) {
 			if (count)
 				printf(", ");
 			printf("%s", flags[i]);
Index: src/pkcs15init/pkcs15-oberthur.c
===================================================================
--- src/pkcs15init/pkcs15-oberthur.c	(revision 4779)
+++ src/pkcs15init/pkcs15-oberthur.c	(working copy)
@@ -61,14 +61,12 @@
 
 static int 
 cosm_write_tokeninfo (struct sc_pkcs15_card *p15card, struct sc_profile *profile, 
-		char *label, unsigned p15_flags)
+		char *label, unsigned p15card_flags, unsigned tinfo_flags)
 {
 	struct sc_context *ctx = p15card->card->ctx;
 	struct sc_file *file = NULL;
-	unsigned mask = SC_PKCS15_CARD_FLAG_PRN_GENERATION 
-		| SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED 
-		| SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED 
-		| SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED;
+	unsigned int p15card_mask = SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED | SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED;
+	unsigned int tinfo_mask = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_LOGIN_REQUIRED;
 	int rv, flags = 0;
 	size_t sz;
 	char *buffer = NULL;
@@ -77,7 +75,7 @@
 		return SC_ERROR_INVALID_ARGUMENTS;
 	
 	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
-	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "cosm_write_tokeninfo() label '%s'; flags 0x%X", label, p15_flags);
+	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "cosm_write_tokeninfo() label '%s'; p15card_flags 0x%X; tinfo_flags  0x%X", label, p15card_flags, tinfo_flags);
 	if (sc_profile_get_file(profile, COSM_TITLE"-token-info", &file))
 		SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCONSISTENT_PROFILE, "Cannot find "COSM_TITLE"-token-info");
 
@@ -90,10 +88,10 @@
 
 	if (label)   
 		strncpy(buffer, label, file->size - 4);
-	else if (p15card->label)
-		snprintf(buffer, file->size - 4, "%s", p15card->label);
-	else if (profile->p15_spec && profile->p15_spec->label)
-		snprintf(buffer, file->size - 4, "%s", profile->p15_spec->label);
+	else if (p15card->tokeninfo->label)
+		snprintf(buffer, file->size - 4, "%s", p15card->tokeninfo->label);
+	else if (profile->p15_spec && profile->p15_spec->tokeninfo->label)
+		snprintf(buffer, file->size - 4, "%s", profile->p15_spec->tokeninfo->label);
 	else
 		snprintf(buffer, file->size - 4, "OpenSC-Token");
 
@@ -101,16 +99,16 @@
 	if (sz < file->size - 4)
 		memset(buffer + sz, ' ', file->size - sz);
 
-	if (p15_flags & SC_PKCS15_CARD_FLAG_PRN_GENERATION)
+	if (tinfo_flags & SC_PKCS15_TOKEN_PRN_GENERATION)
 		flags |= COSM_TOKEN_FLAG_PRN_GENERATION;
 	
-	if (p15_flags & SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED)
+	if (tinfo_flags & SC_PKCS15_TOKEN_LOGIN_REQUIRED)
 		flags |= COSM_TOKEN_FLAG_LOGIN_REQUIRED;
 	
-	if (p15_flags & SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED)
+	if (p15card_flags & SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED)
 		flags |= COSM_TOKEN_FLAG_USER_PIN_INITIALIZED;
 	
-	if (p15_flags & SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED)
+	if (p15card_flags & SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED)
 		flags |= COSM_TOKEN_FLAG_TOKEN_INITIALIZED;
 
 	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "cosm_write_tokeninfo() token label '%s'; oberthur flags 0x%X", buffer, flags);
@@ -123,10 +121,13 @@
 	if (rv > 0)
 		rv = 0;
 
-	p15card->flags = (p15card->flags & ~mask) | p15_flags;
+	p15card->flags = (p15card->flags & ~p15card_mask) | p15card_flags;
+	p15card->tokeninfo->flags = (p15card->tokeninfo->flags & ~tinfo_mask) | tinfo_flags;
 
-	if (profile->p15_spec)
-		profile->p15_spec->flags = (profile->p15_spec->flags & ~mask) | p15_flags;
+	if (profile->p15_spec) {
+		profile->p15_spec->flags = (profile->p15_spec->flags & ~p15card_mask) | p15card_flags;
+		profile->p15_spec->tokeninfo->flags = (profile->p15_spec->tokeninfo->flags & ~tinfo_mask) | tinfo_flags;
+	}
 
 	free(buffer);
 	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
@@ -282,7 +283,7 @@
 	}
 
 	rv = cosm_write_tokeninfo(p15card, profile, NULL,
-		SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED | SC_PKCS15_CARD_FLAG_PRN_GENERATION);
+		SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED, SC_PKCS15_TOKEN_PRN_GENERATION);
 
 	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
 }
@@ -386,10 +387,8 @@
 		SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "cosm_update_pin() failed to change PIN");
 
 		rv = cosm_write_tokeninfo(p15card, profile, NULL,
-			SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED 
-			| SC_PKCS15_CARD_FLAG_PRN_GENERATION
-			| SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED
-			| SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED);
+			SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED | SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED,
+			SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_LOGIN_REQUIRED);
 		SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "cosm_update_pin() failed to update tokeninfo");
 	}
 
@@ -839,10 +838,10 @@
 	memcpy(buf, tinfo->label, label_len);
 	memset(buf  + label_len, ' ', file->size - 4 - label_len);
 
-	if (p15card->flags & SC_PKCS15_CARD_FLAG_PRN_GENERATION)
+	if (p15card->tokeninfo->flags & SC_PKCS15_TOKEN_PRN_GENERATION)
 		flags |= 0x01;
 	
-	if (p15card->flags & SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED)
+	if (p15card->tokeninfo->flags & SC_PKCS15_TOKEN_LOGIN_REQUIRED)
 		flags |= 0x04;
 	
 	if (p15card->flags & SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED)
Index: src/pkcs15init/profile.c
===================================================================
--- src/pkcs15init/profile.c	(revision 4779)
+++ src/pkcs15init/profile.c	(working copy)
@@ -283,11 +283,11 @@
 	pro->pkcs15.do_last_update = 1;
 
 	if (p15card) {
-		p15card->label = strdup("OpenSC Card");
-		p15card->manufacturer_id = strdup("OpenSC Project");
-		p15card->serial_number = strdup("0000");
-		p15card->flags = SC_PKCS15_CARD_FLAG_EID_COMPLIANT;
-		p15card->version = 1;
+		p15card->tokeninfo->label = strdup("OpenSC Card");
+		p15card->tokeninfo->manufacturer_id = strdup("OpenSC Project");
+		p15card->tokeninfo->serial_number = strdup("0000");
+		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_EID_COMPLIANT;
+		p15card->tokeninfo->version = 1;
 
 		/* Set up EF(TokenInfo) and EF(ODF) */
 		p15card->file_tokeninfo = init_file(SC_FILE_TYPE_WORKING_EF);
@@ -822,7 +822,7 @@
 {
 	struct sc_pkcs15_card	*p15card = cur->profile->p15_spec;
 
-	return setstr(&p15card->label, argv[0]);
+	return setstr(&p15card->tokeninfo->label, argv[0]);
 }
 
 static int
@@ -830,7 +830,7 @@
 {
 	struct sc_pkcs15_card	*p15card = cur->profile->p15_spec;
 
-	return setstr(&p15card->manufacturer_id, argv[0]);
+	return setstr(&p15card->tokeninfo->manufacturer_id, argv[0]);
 }
 
 /*
Index: src/pkcs15init/pkcs15-lib.c
===================================================================
--- src/pkcs15init/pkcs15-lib.c	(revision 4779)
+++ src/pkcs15init/pkcs15-lib.c	(working copy)
@@ -781,11 +781,11 @@
 	}
 
 	if (args->label) {
-		if (p15card->label)
-			free(p15card->label);
-		p15card->label = strdup(args->label);
+		if (p15card->tokeninfo->label)
+			free(p15card->tokeninfo->label);
+		p15card->tokeninfo->label = strdup(args->label);
 	}
-	app->label = strdup(p15card->label);
+	app->label = strdup(p15card->tokeninfo->label);
 
 	/* See if we've set an SO PIN */
 	r = sc_pkcs15init_add_object(p15card, profile, SC_PKCS15_AODF, pin_obj);
@@ -2408,21 +2408,13 @@
 	int		r;
 
 	/* set lastUpdate field */
-	if (p15card->last_update != NULL)
-		free(p15card->last_update);
-	p15card->last_update = get_generalized_time(card->ctx);
-	if (p15card->last_update == NULL)
+	if (p15card->tokeninfo->last_update != NULL)
+		free(p15card->tokeninfo->last_update);
+	p15card->tokeninfo->last_update = get_generalized_time(card->ctx);
+	if (p15card->tokeninfo->last_update == NULL)
 		return SC_ERROR_INTERNAL;
 
-	/* create a temporary tokeninfo structure */
-	tokeninfo.version = p15card->version;
-	/* ugly opensc hack, we use the some high flags internaly */
-	tokeninfo.flags = p15card->flags & 0xffffff; 
-	tokeninfo.label = p15card->label;
-	tokeninfo.serial_number = p15card->serial_number;
-	tokeninfo.manufacturer_id = p15card->manufacturer_id;
-	tokeninfo.last_update = p15card->last_update;
-	tokeninfo.preferred_language = p15card->preferred_language;
+	tokeninfo = *(p15card->tokeninfo);
 
 	if (profile->ops->emu_update_tokeninfo)
 		return profile->ops->emu_update_tokeninfo(profile, p15card, &tokeninfo);
@@ -3443,15 +3435,14 @@
 int
 sc_pkcs15init_get_manufacturer(struct sc_profile *profile, const char **res)
 {
-	*res = profile->p15_spec->manufacturer_id;
+	*res = profile->p15_spec->tokeninfo->manufacturer_id;
 	return 0;
 }
 
-
 int
 sc_pkcs15init_get_serial(struct sc_profile *profile, const char **res)
 {
-	*res = profile->p15_spec->serial_number;
+	*res = profile->p15_spec->tokeninfo->serial_number;
 	return 0;
 }
 
@@ -3459,9 +3450,9 @@
 int
 sc_pkcs15init_set_serial(struct sc_profile *profile, const char *serial)
 {
-	if (profile->p15_spec->serial_number)
-		free(profile->p15_spec->serial_number);
-	profile->p15_spec->serial_number = strdup(serial);
+	if (profile->p15_spec->tokeninfo->serial_number)
+		free(profile->p15_spec->tokeninfo->serial_number);
+	profile->p15_spec->tokeninfo->serial_number = strdup(serial);
 
 	return 0;
 }
@@ -3470,7 +3461,7 @@
 int
 sc_pkcs15init_get_label(struct sc_profile *profile, const char **res)
 {
-	*res = profile->p15_spec->label;
+	*res = profile->p15_spec->tokeninfo->label;
 	return 0;
 }
 
Index: src/libopensc/pkcs15-oberthur.c
===================================================================
--- src/libopensc/pkcs15-oberthur.c	(revision 4779)
+++ src/libopensc/pkcs15-oberthur.c	(working copy)
@@ -360,14 +360,14 @@
 
 	flags = *(buff + 0x22) * 0x100 + *(buff + 0x23);
 	
-	p15card->label = strdup(label);
-	p15card->manufacturer_id = strdup("Oberthur/OpenSC");
+	p15card->tokeninfo->label = strdup(label);
+	p15card->tokeninfo->manufacturer_id = strdup("Oberthur/OpenSC");
 
 	if (flags & 0x01)
-		p15card->flags |= SC_PKCS15_CARD_FLAG_PRN_GENERATION;
+		p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION;
 
 	if (flags & 0x04)
-		p15card->flags |= SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED;
+		p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_LOGIN_REQUIRED;
 
 	if (flags & 0x0C)
 		p15card->flags |= SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED;
@@ -375,8 +375,8 @@
 	if (flags & 0x0400)
 		p15card->flags |= SC_PKCS15_CARD_FLAG_TOKEN_INITIALIZED;
 
-	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "label %s", p15card->label);
-	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "manufacturer_id %s", p15card->manufacturer_id);
+	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "label %s", p15card->tokeninfo->label);
+	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "manufacturer_id %s", p15card->tokeninfo->manufacturer_id);
 	
 	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
 }
@@ -508,7 +508,7 @@
 				break;
 
 			/* There are some private keys, so set LOGIN_REQUIRED flag */
-			p15card->flags |= SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED;
+			p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_LOGIN_REQUIRED;
 
 			rv = sc_pkcs15emu_oberthur_add_prvkey(p15card, file_id, size);
 			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
@@ -530,7 +530,7 @@
 				break;
 
 			/* There are private data objects, so set LOGIN_REQUIRED flag */
-			p15card->flags |= SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED;
+			p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_LOGIN_REQUIRED;
 
 			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 1);
 			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
@@ -938,12 +938,12 @@
 	
 	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
 	sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial, sizeof(serial), 0);
-	p15card->serial_number = strdup(serial);
+	p15card->tokeninfo->serial_number = strdup(serial);
 
 	p15card->ops.parse_df = sc_awp_parse_df;
 	p15card->ops.clear = sc_awp_clear;
 	
-	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Oberthur init: serial %s", p15card->serial_number);
+	sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Oberthur init: serial %s", p15card->tokeninfo->serial_number);
 
 	sc_format_path(AWP_PIN_DF, &path);
 	rv = sc_select_file(card, &path, NULL);
Index: src/libopensc/pkcs15-cache.c
===================================================================
--- src/libopensc/pkcs15-cache.c	(revision 4779)
+++ src/libopensc/pkcs15-cache.c	(working copy)
@@ -58,14 +58,14 @@
 	}
 	for (i = 0; i < pathlen; i++)
 		sprintf(pathname + 2*i, "%02X", pathptr[i]);
-	if (p15card->serial_number != NULL) {
-		if (p15card->last_update != NULL)
+	if (p15card->tokeninfo->serial_number != NULL) {
+		if (p15card->tokeninfo->last_update != NULL)
 			r = snprintf(buf, bufsize, "%s/%s_%s_%s", dir,
-			     p15card->serial_number, p15card->last_update,
+			     p15card->tokeninfo->serial_number, p15card->tokeninfo->last_update,
 			     pathname);
 		else
 			r = snprintf(buf, bufsize, "%s/%s_DATE_%s", dir,
-			     p15card->serial_number, pathname);
+			     p15card->tokeninfo->serial_number, pathname);
 		if (r < 0)
 			return SC_ERROR_BUFFER_TOO_SMALL;
 	} else
Index: src/libopensc/pkcs15-openpgp.c
===================================================================
--- src/libopensc/pkcs15-openpgp.c	(revision 4779)
+++ src/libopensc/pkcs15-openpgp.c	(working copy)
@@ -87,23 +87,23 @@
 	size_t		length;
 	int		r, i;
 
-	set_string(&p15card->label, "OpenPGP Card");
-	set_string(&p15card->manufacturer_id, "OpenPGP project");
+	set_string(&p15card->tokeninfo->label, "OpenPGP Card");
+	set_string(&p15card->tokeninfo->manufacturer_id, "OpenPGP project");
 
 	if ((r = read_file(card, "004f", buffer, sizeof(buffer))) < 0)
 		goto failed;
 	sc_bin_to_hex(buffer, (size_t)r, string, sizeof(string), 0);
-	set_string(&p15card->serial_number, string);
-	p15card->version = (buffer[6] << 8) | buffer[7];
+	set_string(&p15card->tokeninfo->serial_number, string);
+	p15card->tokeninfo->version = (buffer[6] << 8) | buffer[7];
 
-	p15card->flags = SC_PKCS15_CARD_FLAG_PRN_GENERATION | SC_PKCS15_CARD_FLAG_EID_COMPLIANT;
+	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_EID_COMPLIANT;
 
 	/* Extract preferred language */
 	r = read_file(card, "00655f2d", string, sizeof(string)-1);
 	if (r < 0)
 		goto failed;
 	string[r] = '\0';
-	set_string(&p15card->preferred_language, string);
+	set_string(&p15card->tokeninfo->preferred_language, string);
 
 	/* Get Application Related Data (006E) */
 	if ((r = sc_get_data(card, 0x006E, buffer, sizeof(buffer))) < 0)
Index: src/libopensc/pkcs15-postecert.c
===================================================================
--- src/libopensc/pkcs15-postecert.c	(revision 4779)
+++ src/libopensc/pkcs15-postecert.c	(working copy)
@@ -193,9 +193,9 @@
 		goto failed;
 	}
 
-	set_string(&p15card->label, "Postecert & Cnipa Card");
-	set_string(&p15card->manufacturer_id, "Postecert");
-	set_string(&p15card->serial_number, "0000");
+	set_string(&p15card->tokeninfo->label, "Postecert & Cnipa Card");
+	set_string(&p15card->tokeninfo->manufacturer_id, "Postecert");
+	set_string(&p15card->tokeninfo->serial_number, "0000");
 
 	sc_read_binary(card, 0, certlen, 2, 0);
 
Index: src/libopensc/pkcs15-tcos.c
===================================================================
--- src/libopensc/pkcs15-tcos.c	(revision 4779)
+++ src/libopensc/pkcs15-tcos.c	(working copy)
@@ -279,8 +279,8 @@
 	sprintf(dir,"%04X", f->id);
 	sc_file_free(f);
 
-	p15card->manufacturer_id = strdup("TeleSec GmbH");
-	p15card->label = strdup(card->type==SC_CARD_TYPE_TCOS_V3 ? "NetKey V3 Card" : "NetKey Card");
+	p15card->tokeninfo->manufacturer_id = strdup("TeleSec GmbH");
+	p15card->tokeninfo->label = strdup(card->type==SC_CARD_TYPE_TCOS_V3 ? "NetKey V3 Card" : "NetKey Card");
 	keylen= card->type==SC_CARD_TYPE_TCOS_V3 ? 2048 : 1024;
 	c_auth= card->type==SC_CARD_TYPE_TCOS_V3 ? "C500" : "C100";
 
@@ -360,8 +360,8 @@
 	sc_pkcs15_card_t *p15card
 ){
 	if(insert_cert(p15card,"8000DF01C000", 0x45, 1, "Signatur Zertifikat")) return 1;
-	p15card->manufacturer_id = strdup("Deutsche Post");
-	p15card->label = strdup("SignTrust Card");
+	p15card->tokeninfo->manufacturer_id = strdup("Deutsche Post");
+	p15card->tokeninfo->label = strdup("SignTrust Card");
 
 	insert_cert(p15card,"800082008220", 0x46, 1, "Verschluesselungs Zertifikat");
 	insert_cert(p15card,"800083008320", 0x47, 1, "Authentifizierungs Zertifikat");
@@ -390,8 +390,8 @@
 	sc_pkcs15_card_t *p15card
 ){
 	if(insert_cert(p15card,"3000C500", 0x45, 0, "Signatur Zertifikat")) return 1;
-	p15card->manufacturer_id = strdup("DATEV");
-	p15card->label = strdup("DATEV Classic");
+	p15card->tokeninfo->manufacturer_id = strdup("DATEV");
+	p15card->tokeninfo->label = strdup("DATEV Classic");
 
 	insert_cert(p15card,"DF02C200", 0x46, 0, "Verschluesselungs Zertifikat");
 	insert_cert(p15card,"DF02C500", 0x47, 0, "Authentifizierungs Zertifikat");
@@ -412,8 +412,8 @@
 	sc_pkcs15_card_t *p15card
 ){
 	if(!insert_cert(p15card,"41004352", 0x45, 1, "Zertifikat 1")){
-		p15card->manufacturer_id = strdup("JLU Giessen");
-		p15card->label = strdup("JLU Giessen Card");
+		p15card->tokeninfo->manufacturer_id = strdup("JLU Giessen");
+		p15card->tokeninfo->label = strdup("JLU Giessen Card");
 
 		insert_cert(p15card,"41004353", 0x46, 1, "Zertifikat 2");
 		insert_cert(p15card,"41004354", 0x47, 1, "Zertifikat 3");
@@ -422,8 +422,8 @@
 		insert_key(p15card,"41005105", 0x47, 0x85, 1024, 1, "Schluessel 3");
 
 	} else if(!insert_cert(p15card,"41014352", 0x45, 1, "Zertifikat 1")){
-		p15card->manufacturer_id = strdup("TU Darmstadt");
-		p15card->label = strdup("TUD Card");
+		p15card->tokeninfo->manufacturer_id = strdup("TU Darmstadt");
+		p15card->tokeninfo->label = strdup("TUD Card");
 
 		insert_cert(p15card,"41014353", 0x46, 1, "Zertifikat 2");
 		insert_cert(p15card,"41014354", 0x47, 1, "Zertifikat 3");
@@ -467,7 +467,7 @@
 	}
         sc_bin_to_hex(serialnr.value, serialnr.len , serial, sizeof(serial), 0);
 	serial[19] = '\0';
-        p15card->serial_number = strdup(serial);
+        p15card->tokeninfo->serial_number = strdup(serial);
 
 	if(!detect_netkey(p15card)) return SC_SUCCESS;
 	if(!detect_signtrust(p15card)) return SC_SUCCESS;
Index: src/libopensc/pkcs15-esinit.c
===================================================================
--- src/libopensc/pkcs15-esinit.c	(revision 4779)
+++ src/libopensc/pkcs15-esinit.c	(working copy)
@@ -56,20 +56,20 @@
 	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
 	if (r != SC_SUCCESS)
 		return SC_ERROR_INTERNAL;
-	if (p15card->serial_number)
-		free(p15card->serial_number);
-	p15card->serial_number = malloc(strlen(buf) + 1);
-	if (!p15card->serial_number)
+	if (p15card->tokeninfo->serial_number)
+		free(p15card->tokeninfo->serial_number);
+	p15card->tokeninfo->serial_number = malloc(strlen(buf) + 1);
+	if (!p15card->tokeninfo->serial_number)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->serial_number, buf);
+	strcpy(p15card->tokeninfo->serial_number, buf);
 
 	/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
-	if (p15card->manufacturer_id)
-		free(p15card->manufacturer_id);
-	p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1);
-	if (!p15card->manufacturer_id)
+	if (p15card->tokeninfo->manufacturer_id)
+		free(p15card->tokeninfo->manufacturer_id);
+	p15card->tokeninfo->manufacturer_id = malloc(strlen(MANU_ID) + 1);
+	if (!p15card->tokeninfo->manufacturer_id)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->manufacturer_id, MANU_ID);
+	strcpy(p15card->tokeninfo->manufacturer_id, MANU_ID);
 
 	return SC_SUCCESS;
 }
Index: src/libopensc/pkcs15-piv.c
===================================================================
--- src/libopensc/pkcs15-piv.c	(revision 4779)
+++ src/libopensc/pkcs15-piv.c	(working copy)
@@ -433,8 +433,8 @@
 	/* could read this off card if needed */
 
 	/* CSP does not like a - in the name */
-	p15card->label = strdup("PIV_II");
-	p15card->manufacturer_id = strdup(MANU_ID);
+	p15card->tokeninfo->label = strdup("PIV_II");
+	p15card->tokeninfo->manufacturer_id = strdup(MANU_ID);
 
 	/*
 	 * get serial number 
@@ -446,10 +446,10 @@
 	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
 	if (r < 0) {
 		sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,"sc_card_ctl rc=%d",r);
-		p15card->serial_number = strdup("00000000");
+		p15card->tokeninfo->serial_number = strdup("00000000");
 	} else {
 		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
-		p15card->serial_number = strdup(buf);
+		p15card->tokeninfo->serial_number = strdup(buf);
 	}
 
 	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "PIV-II adding objects...");
Index: src/libopensc/pkcs15.c
===================================================================
--- src/libopensc/pkcs15.c	(revision 4779)
+++ src/libopensc/pkcs15.c	(working copy)
@@ -458,6 +458,13 @@
 	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
 	if (p15card == NULL)
 		return NULL;
+
+	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
+	if (p15card->tokeninfo == NULL) {
+		free(p15card);
+		return NULL;
+	}
+
 	p15card->magic = SC_PKCS15_CARD_MAGIC;
 	return p15card;
 }
@@ -493,21 +500,22 @@
 	if (p15card->file_unusedspace != NULL)
 		sc_file_free(p15card->file_unusedspace);
 	p15card->magic = 0;
-	if (p15card->label != NULL)
-		free(p15card->label);
-	if (p15card->serial_number != NULL)
-		free(p15card->serial_number);
-	if (p15card->manufacturer_id != NULL)
-		free(p15card->manufacturer_id);
-	if (p15card->last_update != NULL)
-		free(p15card->last_update);
-	if (p15card->preferred_language != NULL)
-		free(p15card->preferred_language);
-	if (p15card->seInfo != NULL) {
-		for (i = 0; i < p15card->num_seInfo; i++)
-			free(p15card->seInfo[i]);
-		free(p15card->seInfo);
+	if (p15card->tokeninfo->label != NULL)
+		free(p15card->tokeninfo->label);
+	if (p15card->tokeninfo->serial_number != NULL)
+		free(p15card->tokeninfo->serial_number);
+	if (p15card->tokeninfo->manufacturer_id != NULL)
+		free(p15card->tokeninfo->manufacturer_id);
+	if (p15card->tokeninfo->last_update != NULL)
+		free(p15card->tokeninfo->last_update);
+	if (p15card->tokeninfo->preferred_language != NULL)
+		free(p15card->tokeninfo->preferred_language);
+	if (p15card->tokeninfo->seInfo != NULL) {
+		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
+			free(p15card->tokeninfo->seInfo[i]);
+		free(p15card->tokeninfo->seInfo);
 	}
+	free(p15card->tokeninfo);
 	free(p15card);
 }
 
@@ -519,8 +527,9 @@
 	if (p15card->ops.clear)
 		p15card->ops.clear(p15card);
 
-	p15card->version = 0;
-	p15card->flags   = 0;
+	p15card->flags = 0;
+	p15card->tokeninfo->version = 0;
+	p15card->tokeninfo->flags   = 0;
 	while (p15card->obj_list)   {
 		struct sc_pkcs15_object *obj = p15card->obj_list;
 
@@ -547,33 +556,33 @@
 		sc_file_free(p15card->file_unusedspace);
 		p15card->file_unusedspace = NULL;
 	}
-	if (p15card->label != NULL) {
-		free(p15card->label);
-		p15card->label = NULL;
+	if (p15card->tokeninfo->label != NULL) {
+		free(p15card->tokeninfo->label);
+		p15card->tokeninfo->label = NULL;
 	}
-	if (p15card->serial_number != NULL) {
-		free(p15card->serial_number);
-		p15card->serial_number = NULL;
+	if (p15card->tokeninfo->serial_number != NULL) {
+		free(p15card->tokeninfo->serial_number);
+		p15card->tokeninfo->serial_number = NULL;
 	}
-	if (p15card->manufacturer_id != NULL) {
-		free(p15card->manufacturer_id);
-		p15card->manufacturer_id = NULL;
+	if (p15card->tokeninfo->manufacturer_id != NULL) {
+		free(p15card->tokeninfo->manufacturer_id);
+		p15card->tokeninfo->manufacturer_id = NULL;
 	}
-	if (p15card->last_update != NULL) {
-		free(p15card->last_update);
-		p15card->last_update = NULL;
+	if (p15card->tokeninfo->last_update != NULL) {
+		free(p15card->tokeninfo->last_update);
+		p15card->tokeninfo->last_update = NULL;
 	}
-	if (p15card->preferred_language != NULL) {
-		free(p15card->preferred_language);
-		p15card->preferred_language = NULL;
+	if (p15card->tokeninfo->preferred_language != NULL) {
+		free(p15card->tokeninfo->preferred_language);
+		p15card->tokeninfo->preferred_language = NULL;
 	}
-	if (p15card->seInfo != NULL) {
+	if (p15card->tokeninfo->seInfo != NULL) {
 		size_t i;
-		for (i = 0; i < p15card->num_seInfo; i++)
-			free(p15card->seInfo[i]);
-		free(p15card->seInfo);
-		p15card->seInfo     = NULL;
-		p15card->num_seInfo = 0;
+		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
+			free(p15card->tokeninfo->seInfo[i]);
+		free(p15card->tokeninfo->seInfo);
+		p15card->tokeninfo->seInfo     = NULL;
+		p15card->tokeninfo->num_seInfo = 0;
 	}
 }
 
@@ -724,31 +733,19 @@
 	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 	if (err != SC_SUCCESS)
 		goto end;
-	p15card->version         = tokeninfo.version;
-	p15card->label           = tokeninfo.label;
-	p15card->serial_number   = tokeninfo.serial_number;
-	p15card->manufacturer_id = tokeninfo.manufacturer_id;
-	p15card->last_update     = tokeninfo.last_update;
-	p15card->flags           = tokeninfo.flags;
-	p15card->preferred_language = tokeninfo.preferred_language;
-	p15card->seInfo          = tokeninfo.seInfo;
-	p15card->num_seInfo      = tokeninfo.num_seInfo;
 
-	memcpy(&p15card->supported_algos, &tokeninfo.supported_algos, sizeof(p15card->supported_algos));
-	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS && p15card->supported_algos[ii].reference; ii++)
-		sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "algo[%i]: ref:0x%X;mech:0x%X;op:0x%X;algo_ref:0x%X", ii,
-				p15card->supported_algos[ii].reference, p15card->supported_algos[ii].mechanism,
-				p15card->supported_algos[ii].operations, p15card->supported_algos[ii].algo_ref);
+	*(p15card->tokeninfo) = tokeninfo;
 
-	if (!p15card->serial_number && card->serialnr.len)   {
+	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
 		char *serial = calloc(1, card->serialnr.len*2 + 1);
 		size_t ii;
 		
 		for(ii=0;ii<card->serialnr.len;ii++)
 			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 
-		p15card->serial_number = serial;
-		sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "p15card->serial_number %s", p15card->serial_number);
+		p15card->tokeninfo->serial_number = serial;
+		sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "p15card->tokeninfo->serial_number %s",
+			p15card->tokeninfo->serial_number);
 	}
 
 	ok = 1;
@@ -834,12 +831,12 @@
 	if (strcmp(p15card->card->driver->short_name,"cardos") == 0) {
 
 		/* D-Trust cards (D-TRUST, D-SIGN) */
-		if (strstr(p15card->label,"D-TRUST") != NULL
-			|| strstr(p15card->label,"D-SIGN") != NULL) {
+		if (strstr(p15card->tokeninfo->label,"D-TRUST") != NULL
+			|| strstr(p15card->tokeninfo->label,"D-SIGN") != NULL) {
 
 			/* D-TRUST Card 2.0 2cc (standard cards, which always add
 			 * SHA1 prefix itself */
-			if (strstr(p15card->label, "2cc") != NULL) {
+			if (strstr(p15card->tokeninfo->label, "2cc") != NULL) {
 				p15card->card->caps |= SC_CARD_CAP_ONLY_RAW_HASH_STRIPPED;
 				sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, "D-TRUST 2cc card detected, only SHA1 works with this card");
 				/* XXX: add detection when other hash than SHA1 is used with
@@ -849,7 +846,7 @@
 
 			/* D-SIGN multicard 2.0 2ca (cards working with all types of hashes
 			 * and no addition of prefix) */
-			else if (strstr(p15card->label, "2ca") != NULL) {
+			else if (strstr(p15card->tokeninfo->label, "2ca") != NULL) {
 				p15card->card->caps |= SC_CARD_CAP_ONLY_RAW_HASH;
 				sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, "D-TRUST 2ca card detected");
 			}
Index: src/libopensc/pkcs15.h
===================================================================
--- src/libopensc/pkcs15.h	(revision 4779)
+++ src/libopensc/pkcs15.h	(working copy)
@@ -434,21 +434,14 @@
 
 typedef struct sc_pkcs15_card {
 	sc_card_t *card;
-	char *label;
-	/* fields from TokenInfo: */
-	int version;
-	char *serial_number, *manufacturer_id;
-	char *last_update;
 	unsigned int flags;
 
-	struct sc_supported_algo_info supported_algos[SC_MAX_SUPPORTED_ALGORITHMS];
-
 	sc_file_t *file_app;
 	sc_file_t *file_tokeninfo, *file_odf, *file_unusedspace;
 
 	struct sc_pkcs15_df *df_list;
 	struct sc_pkcs15_object *obj_list;
-	int record_lengths[SC_PKCS15_DF_TYPE_COUNT];
+	sc_pkcs15_tokeninfo_t *tokeninfo;
 	sc_pkcs15_unusedspace_t *unusedspace_list;
 	int unusedspace_read;
 
@@ -458,22 +451,22 @@
 		int pin_cache_counter;
 	} opts;
 
-	sc_pkcs15_sec_env_info_t **seInfo;
-	size_t num_seInfo;
 
 	unsigned int magic;
 
 	void *dll_handle;		/* shared lib for emulated cards */
-	char *preferred_language;
 
 	struct sc_pkcs15_operations ops;
 
 } sc_pkcs15_card_t;
 
-#define SC_PKCS15_CARD_FLAG_READONLY			0x01
-#define SC_PKCS15_CARD_FLAG_LOGIN_REQUIRED		0x02 /* Don't use */
-#define SC_PKCS15_CARD_FLAG_PRN_GENERATION		0x04
-#define SC_PKCS15_CARD_FLAG_EID_COMPLIANT		0x08
+/* flags suitable for sc_pkcs15_tokeninfo_t */
+#define SC_PKCS15_TOKEN_READONLY			0x01
+#define SC_PKCS15_TOKEN_LOGIN_REQUIRED			0x02 /* Don't use */
+#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
+#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
+
+/* flags suitable for sc_pkcs15_card_t */
 #define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
 #define SC_PKCS15_CARD_FLAG_FIX_INTEGERS		0x04000000
 #define SC_PKCS15_CARD_FLAG_USER_PIN_INITIALIZED	0x08000000
Index: src/libopensc/pkcs15-infocamere.c
===================================================================
--- src/libopensc/pkcs15-infocamere.c	(revision 4779)
+++ src/libopensc/pkcs15-infocamere.c	(working copy)
@@ -287,16 +287,16 @@
 		return SC_ERROR_WRONG_CARD;
 	}
 
-	set_string(&p15card->serial_number, serial);
+	set_string(&p15card->tokeninfo->serial_number, serial);
 
 	if (ef_gdo[len_iccsn + 6] == 0x02)
-		set_string(&p15card->label, "Infocamere 1202 Card");
+		set_string(&p15card->tokeninfo->label, "Infocamere 1202 Card");
 	else {
-		set_string(&p15card->label, "Infocamere 1203 Card");
+		set_string(&p15card->tokeninfo->label, "Infocamere 1203 Card");
 		change_sign = 1;
 	}
 
-	set_string(&p15card->manufacturer_id, "Infocamere");
+	set_string(&p15card->tokeninfo->manufacturer_id, "Infocamere");
 
 	authority = 0;
 
@@ -599,9 +599,9 @@
 	sc_read_binary(card, 15, serial, 15, 0);
 	serial[15] = '\0';
 
-	set_string(&p15card->serial_number, (char *)serial);
-	set_string(&p15card->label, "Infocamere 1400 Card");
-	set_string(&p15card->manufacturer_id, "Infocamere");
+	set_string(&p15card->tokeninfo->serial_number, (char *)serial);
+	set_string(&p15card->tokeninfo->label, "Infocamere 1400 Card");
+	set_string(&p15card->tokeninfo->manufacturer_id, "Infocamere");
 
 	if ((r = loadCertificate(p15card, 0, certPath[0], certLabel[0])) !=
 	    SC_SUCCESS) {
@@ -724,9 +724,9 @@
 	sc_read_binary(card, 30, serial, 16, 0);
 	serial[16] = '\0';
 
-	set_string(&p15card->serial_number, (char *) serial);
-	set_string(&p15card->label, "Infocamere 1600 Card");
-	set_string(&p15card->manufacturer_id, "Infocamere");
+	set_string(&p15card->tokeninfo->serial_number, (char *) serial);
+	set_string(&p15card->tokeninfo->label, "Infocamere 1600 Card");
+	set_string(&p15card->tokeninfo->manufacturer_id, "Infocamere");
 
 	/* Adding certificates.
 	 * Certificates are stored in a ZLib compressed form with
Index: src/libopensc/pkcs15-actalis.c
===================================================================
--- src/libopensc/pkcs15-actalis.c	(revision 4779)
+++ src/libopensc/pkcs15-actalis.c	(working copy)
@@ -191,9 +191,9 @@
 		return SC_ERROR_WRONG_CARD;
 	
 			
-	set_string(&p15card->label, "Actalis");
-	set_string(&p15card->manufacturer_id, "Actalis");
-	set_string(&p15card->serial_number, (char *)serial);
+	set_string(&p15card->tokeninfo->label, "Actalis");
+	set_string(&p15card->tokeninfo->manufacturer_id, "Actalis");
+	set_string(&p15card->tokeninfo->serial_number, (char *)serial);
 
 #ifdef ENABLE_ZLIB
 	for (i = 0; i < 3; i++) {
Index: src/libopensc/pkcs15-starcert.c
===================================================================
--- src/libopensc/pkcs15-starcert.c	(revision 4779)
+++ src/libopensc/pkcs15-starcert.c	(working copy)
@@ -165,21 +165,21 @@
 	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
 	if (r != SC_SUCCESS)
 		return SC_ERROR_INTERNAL;
-	if (p15card->serial_number)
-		free(p15card->serial_number);
-	p15card->serial_number = malloc(strlen(buf) + 1);
-	if (!p15card->serial_number)
+	if (p15card->tokeninfo->serial_number)
+		free(p15card->tokeninfo->serial_number);
+	p15card->tokeninfo->serial_number = malloc(strlen(buf) + 1);
+	if (!p15card->tokeninfo->serial_number)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->serial_number, buf);
+	strcpy(p15card->tokeninfo->serial_number, buf);
 	/* the TokenInfo version number */
-	p15card->version = 0;
+	p15card->tokeninfo->version = 0;
 	/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
-	if (p15card->manufacturer_id)
-		free(p15card->manufacturer_id);
-	p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1);
-	if (!p15card->manufacturer_id)
+	if (p15card->tokeninfo->manufacturer_id)
+		free(p15card->tokeninfo->manufacturer_id);
+	p15card->tokeninfo->manufacturer_id = malloc(strlen(MANU_ID) + 1);
+	if (!p15card->tokeninfo->manufacturer_id)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->manufacturer_id, MANU_ID);
+	strcpy(p15card->tokeninfo->manufacturer_id, MANU_ID);
 
 	/* set certs */
 	for (i = 0; certs[i].label; i++) {
Index: src/libopensc/pkcs15-tccardos.c
===================================================================
--- src/libopensc/pkcs15-tccardos.c	(revision 4779)
+++ src/libopensc/pkcs15-tccardos.c	(working copy)
@@ -306,27 +306,27 @@
 	if (r != SC_SUCCESS)
 		return r;
 	/* set card label */
-	if (p15card->label != NULL)
-		free(p15card->label);
-	p15card->label = strdup(TC_CARDOS_LABEL);
-	if (p15card->label == NULL)
+	if (p15card->tokeninfo->label != NULL)
+		free(p15card->tokeninfo->label);
+	p15card->tokeninfo->label = strdup(TC_CARDOS_LABEL);
+	if (p15card->tokeninfo->label == NULL)
 		return SC_ERROR_OUT_OF_MEMORY;
 	/* set the manufacturer ID */
-	if (p15card->manufacturer_id != NULL)
-		free(p15card->manufacturer_id);
-	p15card->manufacturer_id = strdup(MANU_ID);
-	if (p15card->manufacturer_id == NULL)
+	if (p15card->tokeninfo->manufacturer_id != NULL)
+		free(p15card->tokeninfo->manufacturer_id);
+	p15card->tokeninfo->manufacturer_id = strdup(MANU_ID);
+	if (p15card->tokeninfo->manufacturer_id == NULL)
 		return SC_ERROR_OUT_OF_MEMORY;
 	/* set the serial number */
 	r = read_file(p15card->card, "3F002F02", gdo, &gdo_len);
 	if (r != SC_SUCCESS)
 		return SC_ERROR_INTERNAL;
 	sc_bin_to_hex(gdo + 7, 8, hex_buf, sizeof(hex_buf), 0);
-	p15card->serial_number = strdup(hex_buf);
-	if (p15card->serial_number == NULL)
+	p15card->tokeninfo->serial_number = strdup(hex_buf);
+	if (p15card->tokeninfo->serial_number == NULL)
 		return SC_ERROR_OUT_OF_MEMORY;
 	/* the TokenInfo version number */
-	p15card->version = 0;
+	p15card->tokeninfo->version = 0;
 	/* select the application DF */
 	sc_format_path(TC_CARDOS_APP_DF, &path);
 	r = sc_select_file(card, &path, &file);
Index: src/libopensc/pkcs15-atrust-acos.c
===================================================================
--- src/libopensc/pkcs15-atrust-acos.c	(revision 4779)
+++ src/libopensc/pkcs15-atrust-acos.c	(working copy)
@@ -173,31 +173,31 @@
 	r = sc_bin_to_hex(buf, 8, buf2, sizeof(buf2), 0);
 	if (r != SC_SUCCESS)
 		return SC_ERROR_INTERNAL;
-	if (p15card->serial_number)
-		free(p15card->serial_number);
-	p15card->serial_number = malloc(strlen(buf2) + 1);
-	if (!p15card->serial_number)
+	if (p15card->tokeninfo->serial_number)
+		free(p15card->tokeninfo->serial_number);
+	p15card->tokeninfo->serial_number = malloc(strlen(buf2) + 1);
+	if (!p15card->tokeninfo->serial_number)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->serial_number, buf2);
+	strcpy(p15card->tokeninfo->serial_number, buf2);
 
 	/* the TokenInfo version number */
-	p15card->version = 0;
+	p15card->tokeninfo->version = 0;
 
 	/* manufacturer ID */
-	if (p15card->manufacturer_id)
-		free(p15card->manufacturer_id);
-	p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1);
-	if (!p15card->manufacturer_id)
+	if (p15card->tokeninfo->manufacturer_id)
+		free(p15card->tokeninfo->manufacturer_id);
+	p15card->tokeninfo->manufacturer_id = malloc(strlen(MANU_ID) + 1);
+	if (!p15card->tokeninfo->manufacturer_id)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->manufacturer_id, MANU_ID);
+	strcpy(p15card->tokeninfo->manufacturer_id, MANU_ID);
 
 	/* card label */
-	if (p15card->label)
-		free(p15card->label);
-	p15card->label = malloc(strlen(CARD_LABEL) + 1);
-	if (!p15card->label)
+	if (p15card->tokeninfo->label)
+		free(p15card->tokeninfo->label);
+	p15card->tokeninfo->label = malloc(strlen(CARD_LABEL) + 1);
+	if (!p15card->tokeninfo->label)
 		return SC_ERROR_INTERNAL;
-	strcpy(p15card->label, CARD_LABEL);
+	strcpy(p15card->tokeninfo->label, CARD_LABEL);
 
 	/* set certs */
 	for (i = 0; certs[i].label; i++) {
Index: src/libopensc/pkcs15-gemsafeV1.c
===================================================================
--- src/libopensc/pkcs15-gemsafeV1.c	(revision 4779)
+++ src/libopensc/pkcs15-gemsafeV1.c	(working copy)
@@ -231,19 +231,19 @@
 
     sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, "%s: Setting pkcs15 parameters\n", fn_name);
 
-    if (p15card->label)
-    	free(p15card->label);
-    p15card->label = malloc(strlen(APPLET_NAME) + 1);
-    if (!p15card->label)
+    if (p15card->tokeninfo->label)
+    	free(p15card->tokeninfo->label);
+    p15card->tokeninfo->label = malloc(strlen(APPLET_NAME) + 1);
+    if (!p15card->tokeninfo->label)
     	return SC_ERROR_INTERNAL;
-    strcpy(p15card->label, APPLET_NAME);
+    strcpy(p15card->tokeninfo->label, APPLET_NAME);
 
-    if (p15card->serial_number)
-	    free(p15card->serial_number);
-    p15card->serial_number = malloc(strlen(DRIVER_SERIAL_NUMBER) + 1);
-    if (!p15card->serial_number)
+    if (p15card->tokeninfo->serial_number)
+	    free(p15card->tokeninfo->serial_number);
+    p15card->tokeninfo->serial_number = malloc(strlen(DRIVER_SERIAL_NUMBER) + 1);
+    if (!p15card->tokeninfo->serial_number)
 	    return SC_ERROR_INTERNAL;
-    strcpy(p15card->serial_number, DRIVER_SERIAL_NUMBER);
+    strcpy(p15card->tokeninfo->serial_number, DRIVER_SERIAL_NUMBER);
 
     /* the GemSAFE applet version number */
     sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0xdf, 0x03);
@@ -264,15 +264,15 @@
     version = strtod( (const char *)(apdu.resp + 4), &endptr);
     sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, "%s: version (float): %f, version (int): %d\n",
     	    fn_name, version, (int)version);
-    p15card->version = (int)version;
+    p15card->tokeninfo->version = (int)version;
 
     /* the manufacturer ID, in this case GemPlus */
-    if (p15card->manufacturer_id)
-	    free(p15card->manufacturer_id);
-    p15card->manufacturer_id = malloc(strlen(MANU_ID) + 1);
-    if (!p15card->manufacturer_id)
+    if (p15card->tokeninfo->manufacturer_id)
+	    free(p15card->tokeninfo->manufacturer_id);
+    p15card->tokeninfo->manufacturer_id = malloc(strlen(MANU_ID) + 1);
+    if (!p15card->tokeninfo->manufacturer_id)
 	    return SC_ERROR_INTERNAL;
-    strcpy(p15card->manufacturer_id, MANU_ID);
+    strcpy(p15card->tokeninfo->manufacturer_id, MANU_ID);
 
     /* set certs */
     sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, "%s: Setting certificate\n", fn_name);
Index: src/libopensc/pkcs15-pteid.c
===================================================================
--- src/libopensc/pkcs15-pteid.c	(revision 4779)
+++ src/libopensc/pkcs15-pteid.c	(working copy)
@@ -83,16 +83,9 @@
 	r = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t) r);
 	if (r != SC_SUCCESS)
 		goto end;
-	p15card->version         = tokeninfo.version;
-	p15card->label           = tokeninfo.label;
-	p15card->serial_number   = tokeninfo.serial_number;
-	p15card->manufacturer_id = tokeninfo.manufacturer_id;
-	p15card->last_update     = tokeninfo.last_update;
-	p15card->flags           = tokeninfo.flags;
-	p15card->preferred_language = tokeninfo.preferred_language;
-	p15card->seInfo          = tokeninfo.seInfo;
-	p15card->num_seInfo      = tokeninfo.num_seInfo;
 
+	*(p15card->tokeninfo) = tokeninfo;
+
 	/* Card type detection */
 	if (card->type == SC_CARD_TYPE_IAS_PTEID)
 		type = IAS_CARD;
@@ -103,9 +96,9 @@
 		goto end;
 	}
 
-	p15card->flags = SC_PKCS15_CARD_FLAG_PRN_GENERATION
-	                 | SC_PKCS15_CARD_FLAG_EID_COMPLIANT
-	                 | SC_PKCS15_CARD_FLAG_READONLY;
+	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION
+				  | SC_PKCS15_TOKEN_EID_COMPLIANT
+				  | SC_PKCS15_TOKEN_READONLY;
 
 	/* TODO: Use the cardholder's name?  */
 	/* TODO: Use Portuguese descriptions? */
Index: src/libopensc/pkcs15-gemsafeGPK.c
===================================================================
--- src/libopensc/pkcs15-gemsafeGPK.c	(revision 4779)
+++ src/libopensc/pkcs15-gemsafeGPK.c	(working copy)
@@ -219,14 +219,14 @@
 
 	/* could read this off card if needed */
 
-	p15card->label = strdup("GemSAFE");
-	p15card->manufacturer_id = strdup(MANU_ID);
+	p15card->tokeninfo->label = strdup("GemSAFE");
+	p15card->tokeninfo->manufacturer_id = strdup(MANU_ID);
 	/* get serial number */
         r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
         r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
         if (r != SC_SUCCESS)
                 return SC_ERROR_INTERNAL;
-        p15card->serial_number = strdup(buf);
+        p15card->tokeninfo->serial_number = strdup(buf);
 
 	/* test if we have a gemsafe app df */
 	memset(&path, 0, sizeof(path));
Index: src/libopensc/pkcs15-esteid.c
===================================================================
--- src/libopensc/pkcs15-esteid.c	(revision 4779)
+++ src/libopensc/pkcs15-esteid.c	(working copy)
@@ -72,9 +72,9 @@
 	int r, i, flags;
 	sc_path_t tmppath;
 
-	set_string (&p15card->label, "ID-kaart");
-	set_string (&p15card->manufacturer_id, "AS Sertifitseerimiskeskus");
-	p15card->version = 2; /* Increases as the code changes for EstEID happen, not only in this file */
+	set_string (&p15card->tokeninfo->label, "ID-kaart");
+	set_string (&p15card->tokeninfo->manufacturer_id, "AS Sertifitseerimiskeskus");
+	p15card->tokeninfo->version = 2; /* Increases as the code changes for EstEID happen, not only in this file */
 
 	/* Select application directory */
 	sc_format_path ("3f00eeee5044", &tmppath);
@@ -85,7 +85,7 @@
 	r = sc_read_record (card, SC_ESTEID_PD_DOCUMENT_NR, buff, sizeof(buff), SC_RECORD_BY_REC_NR);
 	SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "read document number failed");
 	buff[r] = '\0';
-	set_string (&p15card->serial_number, (const char *) buff);
+	set_string (&p15card->tokeninfo->serial_number, (const char *) buff);
 
 #ifdef ENABLE_ICONV
 	/* Read the name of the cardholder and convert it into UTF-8 */
@@ -116,11 +116,11 @@
 	*outptr = '\0';
 	iconv_close(iso_utf);
 	snprintf(label, sizeof(label), "%s %s", name1, name2);
-	set_string (&p15card->label, label);
+	set_string (&p15card->tokeninfo->label, label);
 #endif
-	p15card->flags = SC_PKCS15_CARD_FLAG_PRN_GENERATION
-	                 | SC_PKCS15_CARD_FLAG_EID_COMPLIANT
-	                 | SC_PKCS15_CARD_FLAG_READONLY;
+	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION
+				  | SC_PKCS15_TOKEN_EID_COMPLIANT
+				  | SC_PKCS15_TOKEN_READONLY;
 
 	/* EstEID uses 1024b RSA */
 	card->algorithm_count = 0;
Index: src/libopensc/pkcs15-itacns.c
===================================================================
--- src/libopensc/pkcs15-itacns.c	(revision 4779)
+++ src/libopensc/pkcs15-itacns.c	(working copy)
@@ -505,7 +505,7 @@
 			sc_pkcs15_free_data_object(p15_personaldata);
 			return SC_SUCCESS;
 		}
-		set_string(&p15card->label, fullname);
+		set_string(&p15card->tokeninfo->label, fullname);
 	}
 	sc_pkcs15_free_data_object(p15_personaldata);
 	return SC_SUCCESS;
@@ -703,7 +703,7 @@
 
 	SC_FUNC_CALLED(p15card->card->ctx, 1);
 
-	set_string(&p15card->label, p15card->card->name);
+	set_string(&p15card->tokeninfo->label, p15card->card->name);
 	if(p15card->card->drv_data) {
 		unsigned int mask_code, ic_code;
 		char buffer[256];
@@ -718,8 +718,8 @@
 		snprintf(buffer, sizeof(buffer), "IC: %s; mask: %s",
 			iso7816_ic_manufacturers[ic_code],
 			itacns_mask_manufacturers[mask_code]);
-		set_string(&p15card->manufacturer_id, buffer);
-		p15card->version = (data->os_version_h << 8
+		set_string(&p15card->tokeninfo->manufacturer_id, buffer);
+		p15card->tokeninfo->version = (data->os_version_h << 8
 			| data->os_version_l);
 	}
 
@@ -732,7 +732,7 @@
 		if (bytes < 0) return bytes;
 		if (bytes > 16) return -1;
 		serial[bytes] = '\0';
-		set_string(&p15card->serial_number, (char*)serial);
+		set_string(&p15card->tokeninfo->serial_number, (char*)serial);
 	}
 
 	/* Is the card a CIE v1? */
Index: src/libopensc/pkcs15-westcos.c
===================================================================
--- src/libopensc/pkcs15-westcos.c	(revision 4779)
+++ src/libopensc/pkcs15-westcos.c	(working copy)
@@ -47,22 +47,22 @@
 	if (file)
 		sc_file_free(file);
 	file = NULL;
-	if (p15card->label != NULL)
-		free(p15card->label);
-	p15card->label = strdup("westcos");
-	if (p15card->manufacturer_id != NULL)
-		free(p15card->manufacturer_id);
-	p15card->manufacturer_id = strdup("CEV");
+	if (p15card->tokeninfo->label != NULL)
+		free(p15card->tokeninfo->label);
+	p15card->tokeninfo->label = strdup("westcos");
+	if (p15card->tokeninfo->manufacturer_id != NULL)
+		free(p15card->tokeninfo->manufacturer_id);
+	p15card->tokeninfo->manufacturer_id = strdup("CEV");
 
 	/* get serial number */
 	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
 	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
 	if (r)
 		goto out;
-	if (p15card->serial_number != NULL)
-		free(p15card->serial_number);
-	p15card->serial_number = strdup(buf);
-	p15card->version = buf[6];
+	if (p15card->tokeninfo->serial_number != NULL)
+		free(p15card->tokeninfo->serial_number);
+	p15card->tokeninfo->serial_number = strdup(buf);
+	p15card->tokeninfo->version = buf[6];
 	sc_format_path("AAAA", &path);
 	r = sc_select_file(card, &path, &file);
 	if (r) 
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to