Index: src/libopensc/card-westcos.c
===================================================================
--- src/libopensc/card-westcos.c	(revision 3720)
+++ src/libopensc/card-westcos.c	(working copy)
@@ -39,10 +39,6 @@
 #define min(a,b) (((a)<(b))?(a):(b))
 #endif
 
-#ifndef min
-#define max(a,b) (((a)>(b))?(a):(b))
-#endif
-
 #define DEFAULT_TRANSPORT_KEY "6f:59:b0:ed:6e:62:46:4a:5d:25:37:68:23:a8:a2:2d"
 
 #define JAVACARD (0x01)
@@ -50,7 +46,7 @@
 #ifdef ENABLE_OPENSSL
 #define DEBUG_SSL
 #ifdef DEBUG_SSL
-static void print_openssl_erreur(void)
+static void print_openssl_error(void)
 {
 	static int charge = 0;
 	long r;
@@ -620,7 +616,7 @@
 		sc_debug(card->ctx, "westcos_create_file\n");
 	memset(buf, 0, sizeof(buf));
 
-	/* clef de transport */
+	/* transport key */
 	r = sc_card_ctl(card, SC_CARDCTL_WESTCOS_AUT_KEY, NULL);
 	if (r)
 		return (r);
@@ -642,7 +638,7 @@
 	case SC_FILE_TYPE_WORKING_EF:
 		switch (file->ef_structure) {
 		case SC_FILE_EF_TRANSPARENT:
-			buf[0] |= 0x20;	/* pas de support transaction  */
+			buf[0] |= 0x20; /* no transaction support */
 			buf[1] |= 0;
 			_convertion_ac_methode(file, HIGH, SC_AC_OP_READ,
 					       &buf[2], &buf[2 + 4]);
@@ -656,7 +652,7 @@
 			buf[11] = (u8) ((file->size) % 256);
 			break;
 		case SC_FILE_EF_LINEAR_FIXED:
-			buf[0] |= 0x40;	/* pas de support transaction  */
+			buf[0] |= 0x40; /* no transaction support */
 			buf[1] |= 0;
 			_convertion_ac_methode(file, HIGH, SC_AC_OP_READ,
 					       &buf[2], &buf[2 + 4]);
@@ -668,7 +664,7 @@
 			buf[11] = file->record_length;
 			break;
 		case SC_FILE_EF_CYCLIC:
-			buf[0] |= 0x60;	/* pas de support transaction  */
+			buf[0] |= 0x60; /* no transaction support */
 			buf[1] |= 0;
 			_convertion_ac_methode(file, HIGH, SC_AC_OP_READ,
 					       &buf[2], &buf[2 + 4]);
@@ -769,7 +765,9 @@
 					u8 * result, size_t * len)
 {
 	int r;
+#ifdef ENABLE_OPENSSL
 	DES_key_schedule ks1, ks2;
+#endif
 	u8 buf[8];
 	if ((*len) < sizeof(buf))
 		return SC_ERROR_INVALID_ARGUMENTS;
@@ -777,17 +775,21 @@
 	r = sc_get_challenge(card, buf, *len);
 	if (r)
 		return r;
+#ifdef ENABLE_OPENSSL
 	DES_set_key((const_DES_cblock *) & key[0], &ks1);
 	DES_set_key((const_DES_cblock *) & key[8], &ks2);
 	DES_ecb2_encrypt((const_DES_cblock *)buf, (DES_cblock*)result, &ks1, &ks2, DES_ENCRYPT);
-	return 0;
+	return SC_SUCCESS;
+#else
+	return SC_ERROR_NOT_SUPPORTED;
+#endif
 }
 
 static int westcos_pin_cmd(sc_card_t * card, struct sc_pin_cmd_data *data,
 			   int *tries_left)
 {
 	int r;
-	u8 buf[20];		//, result[20];
+	u8 buf[20];
 	sc_apdu_t apdu;
 	size_t len = 0;
 	int pad = 0, use_pin_pad = 0, ins, p1 = 0;
@@ -1177,11 +1179,12 @@
 	priv_data_t *priv_data = NULL;
 	int pad;
 
-#ifdef ENABLE_OPENSSL
+#ifndef ENABLE_OPENSSL
+	r = SC_ERROR_NOT_SUPPORTED;
+#else
 	RSA *rsa = NULL;
 	BIO *mem = BIO_new(BIO_s_mem());
 
-#endif
 	if (card == NULL)
 		return SC_ERROR_INVALID_ARGUMENTS;
 	if (card->ctx->debug >= 1)
@@ -1191,10 +1194,6 @@
 		r = SC_ERROR_OUT_OF_MEMORY;
 		goto out;
 	}
-#ifndef ENABLE_OPENSSL
-	r = SC_ERROR_NOT_SUPPORTED;
-
-#else
 	if ((priv_data->env.flags) & SC_ALGORITHM_RSA_PAD_PKCS1)
 		pad = RSA_PKCS1_PADDING;
 
@@ -1225,13 +1224,13 @@
 	BIO_set_mem_eof_return(mem, -1);
 	if (!d2i_RSAPrivateKey_bio(mem, &rsa)) {
 		if (card->ctx->debug >= 5)
-			sc_debug(card->ctx, "RSA clef invalide, %d\n",
+			sc_debug(card->ctx, "RSA key invalid, %d\n",
 				 ERR_get_error());
 		r = SC_ERROR_UNKNOWN;
 		goto out;
 	}
 
-	/* pkcs11 reroute routine cryptage vers la carte */
+	/* pkcs11 reset openssl functions */
 	rsa->meth = RSA_PKCS1_SSLeay();
 	if (RSA_size(rsa) > outlen) {
 		if (card->ctx->debug >= 5)
@@ -1245,7 +1244,7 @@
 		if (r == -1) {
 
 #ifdef DEBUG_SSL
-			print_openssl_erreur();
+			print_openssl_error();
 
 #endif
 			if (card->ctx->debug >= 5)
@@ -1256,13 +1255,13 @@
 		}
 	}
 
-	else {			/* signature */
+	else {			/* sign */
 
 		r = RSA_private_encrypt(data_len, data, out, rsa, pad);
 		if (r == -1) {
 
 #ifdef DEBUG_SSL
-			print_openssl_erreur();
+			print_openssl_error();
 
 #endif
 			if (card->ctx->debug >= 5)
@@ -1284,15 +1283,12 @@
 	r = outlen;
 
 #endif
-#endif /* ENABLE_OPENSSL */
-      out:
-#ifdef ENABLE_OPENSSL
+out:
 	if (mem)
 		BIO_free(mem);
 	if (rsa)
 		RSA_free(rsa);
-
-#endif
+#endif ENABLE_OPENSSL
 	if (keyfile)
 		sc_file_free(keyfile);
 	return r;
Index: src/pkcs15init/pkcs15-westcos.c
===================================================================
--- src/pkcs15init/pkcs15-westcos.c	(revision 3720)
+++ src/pkcs15init/pkcs15-westcos.c	(working copy)
@@ -35,50 +35,12 @@
 #include <openssl/rsa.h>
 #include <openssl/evp.h>
 #include <openssl/pem.h>
-
-
 #include <openssl/err.h>
 #include <openssl/bio.h>
 #endif
 
 extern int sc_check_sw(sc_card_t *card, unsigned int sw1, unsigned int sw2);
 
-#if 0
-/*
- * Get private and public key file
- */
-static int _westcos_get_keyfiles(sc_profile_t *profile, sc_card_t *card,
-                       const sc_path_t *df_path,
-                       sc_file_t **prkf, sc_file_t **pukf)
-{
-	sc_path_t       path = *df_path;
-	int             r;
-
-	/* Get the private key file */
-	r = SC_ERROR_NOT_SUPPORTED; //sc_profile_get_file_by_path(profile, &path, prkf);
-	if (r < 0) {
-		char pbuf[SC_MAX_PATH_STRING_SIZE];
-	
-		r = sc_path_print(pbuf, sizeof(pbuf), &path);
-		if (r != SC_SUCCESS)
-			pbuf[0] = '\0';
-
-		return r;
-	}
-	
-	/* Get the public key file */
-	path.len -= 2;
-	sc_append_file_id(&path, 0x1012);
-	r = SC_ERROR_NOT_SUPPORTED; //sc_profile_get_file_by_path(profile, &path, pukf);
-	if (r < 0) {
-		sc_file_free(*prkf);
-		return r;
-	}
-
-	return 0;
-}
-#endif /* currently unused */
-
 static int westcos_pkcs15init_init_card(sc_profile_t *profile, 
 						sc_card_t *card)
 {
@@ -100,7 +62,6 @@
 
 	/* Create the application DF */
 	r = sc_pkcs15init_create_file(profile, card, df);
-	//if(r) return r;
 
 	r = sc_select_file(card, &df->path, NULL);
 	if(r) return r;
@@ -108,20 +69,7 @@
 	return 0;
 }
 
-#if 0
 /*
-* Create a PIN domain (i.e. a sub-directory holding a user PIN)
-*/
-static int westcos_pkcs15init_create_domain(sc_profile_t *profile, 
-						sc_card_t *card,
-						const sc_pkcs15_id_t *id, 
-						sc_file_t **ret)
-{
-	return SC_ERROR_NOT_SUPPORTED; //sc_pkcs15_create_pin_domain(profile, card, id, ret);
-}
-#endif /* currently unused */
-
-/*
  * Select the PIN reference
  */
 static int westcos_pkcs15_select_pin_reference(sc_profile_t *profile, 
@@ -179,8 +127,6 @@
 		if(r) return (r);
 	}
 
-	//r = sc_pkcs15init_create_file(profile, card, file);
-
 	if(file)
 		sc_file_free(file);
 
@@ -308,24 +254,6 @@
 						sc_pkcs15_prkey_t *key)
 {
 	return SC_ERROR_NOT_SUPPORTED;
-
-#if 0
-	int             r;
-	sc_file_t       *keyfile;
-	sc_pkcs15_prkey_info_t *key_info = (sc_pkcs15_prkey_info_t *) obj->data;
-
-	if (obj->type != SC_PKCS15_TYPE_PRKEY_RSA) {
-		return SC_ERROR_NOT_SUPPORTED;
-	}
-
-	r = SC_ERROR_NOT_SUPPORTED; //sc_profile_get_file_by_path(profile, &key_info->path, &keyfile);
-	if (r < 0) return r;
-
-	//r = sc_pkcs15init_update_file(profile, card, keyfile, &key->der.data, &key->der.len);
-
-	//sc_file_free(keyfile);
-	return r;
-#endif 
 }
 
 /*
@@ -355,7 +283,7 @@
 		return SC_ERROR_NOT_SUPPORTED;
 	}
 
-	if(/*keyfile == NULL ||*/ rsa == NULL || bn == NULL || mem == NULL) 
+	if(rsa == NULL || bn == NULL || mem == NULL) 
 	{
 		r = SC_ERROR_OUT_OF_MEMORY;
 		goto out;
