Hi Martin, On Monday, 18. April 2011, Martin Paljak <mar...@martinpaljak.net> wrote: > On Sun, Apr 17, 2011 at 12:44, Peter Marschall <pe...@adpm.de> wrote: > > please find attached 3 patches to opensc-tool and opensc-explorer: > > > > * [PATCH 1/3] opensc-tool: make list_algorithms() table driven > * The patch has a lot of extra whitespaces at end of lines. Hmm, I do not completely understand. I usually check the spaces at EOL before commit. And I admit I overlooked one (the one in the 159th line of the patch file ;-). In my opinion: 1 != many. All other ones have been in before.
> If you > change the line in options table for list-algorithms, you could maybe > nicely space-align the rest of the table as well ? :) I am not sure I understand your request. I aligned all tables that I either touched or created new. Within each table, all columns start at the same position and the closing brace of a line is at the same position. Between any two column in each table there is minimal 1 space (for the longest item in the left column). Is it possible you are viewing the patches with a variable-width font? Regarding this request I am at a loss. Can you help me? * Do you want me to have all tables the same width overall ? * Do you want me to align the options[] table ? I did not do it as it had nothing to do with my patches and I wanted them to as small as possible. * Do you want me to convert spaces within tables to tabs ? * Do you want me to be space police on these tools and remove all trailing spaces where they occur? > If you use git, > enable the sampel "pre-commit" hook in .git/hooks to detect such > whitespace errors. Thanks that's a good hint. Unfortunately the pre-commit.sample in my installation seems to be different from yours as it does a lot more than simply calling git diff, which is what I do before commits anyway to spot trailing blanks errors (+ testing, of course ;-). > * Why the commented out "none" entries for hashes and paddings and > special handling in the loop for none? As a general rule: please don't > do c++ comments and no commented out code in new commits sorry my fault (I have the habit to list _all_ ID entries in a table ;-) Please find attached the updated first patch. Changes to the previous version: * all ( = 1 ;-) new trailing whitespace removed * commented table contents removed. Sorry for doing it again via mail this time. Give me time until Easter to try github. > > * [PATCH 3/3] opensc-{explorer,tool}: allow sending extended APDUs > > In do_apdu() resp. send_apdu/(, flexibilize parsing the APDU string > > passed so that extended APDUs are accepted a valid APDUs too. > > OK. Also related is #237, at least to the extent that is described in > commend 12 [1]. As you already notices, that's copied code. Pushing it > to a single location and re-using would be a better choice. I wanted to start small ;-) First get the code updated/fixed, then think about getting it into some common library (either a new one or an existing one). I guess the library should be deferred for later. It may need discussions where the code shall go: maybe even directly into libopensc ;-) Best Peter -- Peter Marschall pe...@adpm.de
From 40f710e971744ddf0b15f16c4e7533bedaa11744 Mon Sep 17 00:00:00 2001 From: Peter Marschall <pe...@adpm.de> Date: Sat, 16 Apr 2011 14:28:03 +0200 Subject: [PATCH] opensc-tool: make list_algorithms() table driven Use easily extensible tables instead of explicit coding to display algorithm names and options in list_algorithms. Leverage the new tables to add more RSA hashes. Signed-off-by: Peter Marschall <pe...@adpm.de> --- src/tools/opensc-tool.c | 120 +++++++++++++++++++++++++--------------------- 1 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/tools/opensc-tool.c b/src/tools/opensc-tool.c index aaabf33..5d7ffd5 100644 --- a/src/tools/opensc-tool.c +++ b/src/tools/opensc-tool.c @@ -34,6 +34,12 @@ #include "libopensc/cardctl.h" #include "util.h" +/* type for associations of IDs to names */ +typedef struct _id2str { + unsigned int id; + const char *str; +} id2str_t; + static const char *app_name = "opensc-tool"; static int opt_wait = 0; @@ -556,81 +562,85 @@ static void print_serial(sc_card_t *in_card) static int list_algorithms(void) { int i; - const char *aname; + const char *aname = "unknown"; + + const id2str_t alg_type_names[] = { + { SC_ALGORITHM_RSA, "rsa" }, + { SC_ALGORITHM_DSA, "ec" }, + { SC_ALGORITHM_DES, "des" }, + { SC_ALGORITHM_3DES, "3des" }, + { SC_ALGORITHM_MD5, "md5" }, + { SC_ALGORITHM_SHA1, "sha1" }, + { SC_ALGORITHM_PBKDF2, "pbkdf2" }, + { SC_ALGORITHM_PBES2, "pbes2" }, + { SC_ALGORITHM_GOSTR3410, "gost" }, + { 0, NULL } + }; + const id2str_t alg_flag_names[] = { + { SC_ALGORITHM_ONBOARD_KEY_GEN, "onboard key generation" }, + { SC_ALGORITHM_NEED_USAGE, "needs usage" }, + { 0, NULL } + }; + const id2str_t rsa_flag_names[] = { + { SC_ALGORITHM_RSA_PAD_PKCS1, "pkcs1" }, + { SC_ALGORITHM_RSA_PAD_ANSI, "ansi" }, + { SC_ALGORITHM_RSA_PAD_ISO9796, "iso9796" }, + { SC_ALGORITHM_RSA_HASH_SHA1, "sha1" }, + { SC_ALGORITHM_RSA_HASH_MD5, "MD5" }, + { SC_ALGORITHM_RSA_HASH_MD5_SHA1, "md5-sha1" }, + { SC_ALGORITHM_RSA_HASH_RIPEMD160, "ripemd160" }, + { SC_ALGORITHM_RSA_HASH_SHA256, "sha256" }, + { SC_ALGORITHM_RSA_HASH_SHA384, "sha384" }, + { SC_ALGORITHM_RSA_HASH_SHA512, "sha512" }, + { SC_ALGORITHM_RSA_HASH_SHA224, "sha224" }, + { 0, NULL } + }; if (verbose) printf("Card supports %d algorithm(s)\n\n",card->algorithm_count); for (i=0; i < card->algorithm_count; i++) { - switch (card->algorithms[i].algorithm) { - case SC_ALGORITHM_RSA: - aname = "rsa"; - break; - case SC_ALGORITHM_DSA: - aname = "dsa"; - aname = "ec"; - break; - case SC_ALGORITHM_DES: - aname = "des"; - break; - case SC_ALGORITHM_3DES: - aname = "3des"; - break; - case SC_ALGORITHM_MD5: - aname = "md5"; - break; - case SC_ALGORITHM_SHA1: - aname = "sha1"; - break; - case SC_ALGORITHM_PBKDF2: - aname = "pbkdf2"; - break; - case SC_ALGORITHM_PBES2: - aname = "pbes2"; - break; - case SC_ALGORITHM_GOSTR3410: - aname = "gost"; - break; - default: - aname = "unknown"; - break; - } - + int j; + + /* find algorithm name */ + for (j = 0; alg_type_names[j].str != NULL; j++) { + if (card->algorithms[i].algorithm == alg_type_names[j].id) { + aname = alg_type_names[j].str; + break; + } + } + printf("Algorithm: %s\n", aname); printf("Key length: %d\n", card->algorithms[i].key_length); printf("Flags:"); - if (card->algorithms[i].flags & SC_ALGORITHM_ONBOARD_KEY_GEN) - printf(" onboard key generation"); - if (card->algorithms[i].flags & SC_ALGORITHM_NEED_USAGE) - printf(" needs usage"); + + /* print general flags */ + for (j = 0; alg_flag_names[j].str != NULL; j++) + if (card->algorithms[i].flags & alg_flag_names[j].id) + printf(" %s", alg_flag_names[j].str); + + /* print RSA spcific flags */ if ( card->algorithms[i].algorithm == SC_ALGORITHM_RSA) { int padding = card->algorithms[i].flags & SC_ALGORITHM_RSA_PADS; int hashes = card->algorithms[i].flags & SC_ALGORITHM_RSA_HASHES; + /* print RSA padding flags */ printf(" padding ("); + for (j = 0; rsa_flag_names[j].str != NULL; j++) + if (padding & rsa_flag_names[j].id) + printf(" %s", rsa_flag_names[j].str); if (padding == SC_ALGORITHM_RSA_PAD_NONE) printf(" none"); - if (padding & SC_ALGORITHM_RSA_PAD_PKCS1) - printf(" pkcs1"); - if (padding & SC_ALGORITHM_RSA_PAD_ANSI) - printf(" ansi"); - if (padding & SC_ALGORITHM_RSA_PAD_ISO9796) - printf(" iso9796"); - printf(" ) "); + /* print RSA hash flags */ printf("hashes ("); - if (hashes & SC_ALGORITHM_RSA_HASH_NONE) + for (j = 0; rsa_flag_names[j].str != NULL; j++) + if (hashes & rsa_flag_names[j].id) + printf(" %s", rsa_flag_names[j].str); + if (hashes == SC_ALGORITHM_RSA_HASH_NONE) printf(" none"); - if (hashes & SC_ALGORITHM_RSA_HASH_SHA1) - printf(" sha1"); - if (hashes & SC_ALGORITHM_RSA_HASH_MD5) - printf(" MD5"); - if (hashes & SC_ALGORITHM_RSA_HASH_MD5_SHA1) - printf(" md5-sha1"); - if (hashes & SC_ALGORITHM_RSA_HASH_RIPEMD160) - printf(" ripemd160"); printf(" )"); } printf("\n"); -- 1.7.4.1
_______________________________________________ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel