add '--raw' option to output 8 bit data instead of its hex representation

This commit is contained in:
Nicolas Schneider 2015-09-03 15:09:23 +02:00
parent 29b85b43c0
commit 68796edf36
1 changed files with 27 additions and 10 deletions

View File

@ -50,6 +50,7 @@ static char * opt_auth_id = NULL;
static char * opt_reader = NULL; static char * opt_reader = NULL;
static char * opt_cert = NULL; static char * opt_cert = NULL;
static char * opt_data = NULL; static char * opt_data = NULL;
static int opt_raw = 0;
static char * opt_pubkey = NULL; static char * opt_pubkey = NULL;
static char * opt_outfile = NULL; static char * opt_outfile = NULL;
static char * opt_bind_to_aid = NULL; static char * opt_bind_to_aid = NULL;
@ -82,6 +83,7 @@ enum {
OPT_LIST_APPLICATIONS, OPT_LIST_APPLICATIONS,
OPT_LIST_SKEYS, OPT_LIST_SKEYS,
OPT_NO_PROMPT, OPT_NO_PROMPT,
OPT_RAW,
}; };
#define NELEMENTS(x) (sizeof(x)/sizeof((x)[0])) #define NELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
@ -94,6 +96,7 @@ static const struct option options[] = {
{ "read-certificate", required_argument, NULL, 'r' }, { "read-certificate", required_argument, NULL, 'r' },
{ "list-certificates", no_argument, NULL, 'c' }, { "list-certificates", no_argument, NULL, 'c' },
{ "read-data-object", required_argument, NULL, 'R' }, { "read-data-object", required_argument, NULL, 'R' },
{ "raw", no_argument, NULL, OPT_RAW },
{ "list-data-objects", no_argument, NULL, 'C' }, { "list-data-objects", no_argument, NULL, 'C' },
{ "list-pins", no_argument, NULL, OPT_LIST_PINS }, { "list-pins", no_argument, NULL, OPT_LIST_PINS },
{ "list-secret-keys", no_argument, NULL, OPT_LIST_SKEYS }, { "list-secret-keys", no_argument, NULL, OPT_LIST_SKEYS },
@ -130,6 +133,7 @@ static const char *option_help[] = {
"Reads certificate with ID <arg>", "Reads certificate with ID <arg>",
"Lists certificates", "Lists certificates",
"Reads data object with OID, applicationName or label <arg>", "Reads data object with OID, applicationName or label <arg>",
"Outputs raw 8 bit data to stdout",
"Lists data objects", "Lists data objects",
"Lists PIN codes", "Lists PIN codes",
"Lists secret keys", "Lists secret keys",
@ -346,18 +350,28 @@ print_data_object(const char *kind, const u8*data, size_t data_len)
} }
for (i=0; i < data_len; i++) for (i=0; i < data_len; i++)
fprintf(outf, "%c", data[i]); fprintf(outf, "%c", data[i]);
printf("Dumping (%lu bytes) to file <%s>: <", if (opt_raw) {
(unsigned long) data_len, opt_outfile); for (i=0; i < data_len; i++)
for (i=0; i < data_len; i++) printf("%c", data[i]);
printf(" %02X", data[i]); } else {
printf(" >\n"); printf("Dumping (%lu bytes) to file <%s>: <",
(unsigned long) data_len, opt_outfile);
for (i=0; i < data_len; i++)
printf(" %02X", data[i]);
printf(" >\n");
}
fclose(outf); fclose(outf);
} else { } else {
printf("%s (%lu bytes): <", if (opt_raw) {
kind, (unsigned long) data_len); for (i=0; i < data_len; i++)
for (i=0; i < data_len; i++) printf("%c", data[i]);
printf(" %02X", data[i]); } else {
printf(" >\n"); printf("%s (%lu bytes): <",
kind, (unsigned long) data_len);
for (i=0; i < data_len; i++)
printf(" %02X", data[i]);
printf(" >\n");
}
} }
return 0; return 0;
} }
@ -1931,6 +1945,9 @@ int main(int argc, char * const argv[])
do_read_data_object = 1; do_read_data_object = 1;
action_count++; action_count++;
break; break;
case OPT_RAW:
opt_raw = 1;
break;
case 'C': case 'C':
do_list_data_objects = 1; do_list_data_objects = 1;
action_count++; action_count++;