use switch-case for action args
This commit is contained in:
+17
-6
@@ -754,9 +754,11 @@ int main(int argc, char *argv[]) {
|
|||||||
if(verbosity) {
|
if(verbosity) {
|
||||||
fprintf(stderr, "Now processing for action %d.\n", action);
|
fprintf(stderr, "Now processing for action %d.\n", action);
|
||||||
}
|
}
|
||||||
if(action == action_arg_version) {
|
switch(action) {
|
||||||
|
case action_arg_version:
|
||||||
print_version(&card, verbosity);
|
print_version(&card, verbosity);
|
||||||
} else if(action == action_arg_generate) {
|
break;
|
||||||
|
case action_arg_generate:
|
||||||
if(args_info.slot_arg != slot__NULL) {
|
if(args_info.slot_arg != slot__NULL) {
|
||||||
if(generate_key(&card, args_info.slot_orig, args_info.algorithm_arg, args_info.output_arg, args_info.key_format_arg, verbosity) == false) {
|
if(generate_key(&card, args_info.slot_orig, args_info.algorithm_arg, args_info.output_arg, args_info.key_format_arg, verbosity) == false) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -765,7 +767,8 @@ int main(int argc, char *argv[]) {
|
|||||||
fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n");
|
fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(action == action_arg_setMINUS_mgmMINUS_key) {
|
break;
|
||||||
|
case action_arg_setMINUS_mgmMINUS_key:
|
||||||
if(args_info.new_key_arg) {
|
if(args_info.new_key_arg) {
|
||||||
unsigned char new_key[KEY_LEN];
|
unsigned char new_key[KEY_LEN];
|
||||||
if(parse_key(args_info.new_key_arg, new_key, verbosity) == false) {
|
if(parse_key(args_info.new_key_arg, new_key, verbosity) == false) {
|
||||||
@@ -779,12 +782,14 @@ int main(int argc, char *argv[]) {
|
|||||||
fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n");
|
fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(action == action_arg_reset) {
|
break;
|
||||||
|
case action_arg_reset:
|
||||||
if(reset(&card, verbosity) == false) {
|
if(reset(&card, verbosity) == false) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
printf("Successfully reset the applet.\n");
|
printf("Successfully reset the applet.\n");
|
||||||
} else if(action == action_arg_pinMINUS_retries) {
|
break;
|
||||||
|
case action_arg_pinMINUS_retries:
|
||||||
if(args_info.pin_retries_arg && args_info.puk_retries_arg) {
|
if(args_info.pin_retries_arg && args_info.puk_retries_arg) {
|
||||||
if(set_pin_retries(&card, args_info.pin_retries_arg, args_info.puk_retries_arg, verbosity) == false) {
|
if(set_pin_retries(&card, args_info.pin_retries_arg, args_info.puk_retries_arg, verbosity) == false) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -793,7 +798,8 @@ int main(int argc, char *argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(action == action_arg_importMINUS_key) {
|
break;
|
||||||
|
case action_arg_importMINUS_key:
|
||||||
if(args_info.slot_arg != slot__NULL) {
|
if(args_info.slot_arg != slot__NULL) {
|
||||||
if(import_key(&card, args_info.key_format_arg, args_info.input_arg, args_info.slot_orig, verbosity) == false) {
|
if(import_key(&card, args_info.key_format_arg, args_info.input_arg, args_info.slot_orig, verbosity) == false) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -803,6 +809,11 @@ int main(int argc, char *argv[]) {
|
|||||||
fprintf(stderr, "The import action needs a slot (-s) to operate on.\n");
|
fprintf(stderr, "The import action needs a slot (-s) to operate on.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case action__NULL:
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Wrong action. %d.\n", action);
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user