use switch-case for action args

This commit is contained in:
Klas Lindfors
2014-02-04 15:16:23 +01:00
parent cc0078e224
commit a0da70be7c
+49 -38
View File
@@ -754,55 +754,66 @@ 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) {
print_version(&card, verbosity); case action_arg_version:
} else if(action == action_arg_generate) { print_version(&card, verbosity);
if(args_info.slot_arg != slot__NULL) { break;
if(generate_key(&card, args_info.slot_orig, args_info.algorithm_arg, args_info.output_arg, args_info.key_format_arg, verbosity) == false) { case action_arg_generate:
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) {
return EXIT_FAILURE;
}
} else {
fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else { break;
fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n"); case action_arg_setMINUS_mgmMINUS_key:
return EXIT_FAILURE; if(args_info.new_key_arg) {
} unsigned char new_key[KEY_LEN];
} else if(action == action_arg_setMINUS_mgmMINUS_key) { if(parse_key(args_info.new_key_arg, new_key, verbosity) == false) {
if(args_info.new_key_arg) { return EXIT_FAILURE;
unsigned char new_key[KEY_LEN]; }
if(parse_key(args_info.new_key_arg, new_key, verbosity) == false) { if(set_mgm_key(&card, new_key, verbosity) == false) {
return EXIT_FAILURE;
}
printf("Successfully set new management key.\n");
} else {
fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(set_mgm_key(&card, new_key, verbosity) == false) { break;
case action_arg_reset:
if(reset(&card, verbosity) == false) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("Successfully set new management key.\n"); printf("Successfully reset the applet.\n");
} else { break;
fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n"); case action_arg_pinMINUS_retries:
return EXIT_FAILURE; 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) {
} else if(action == action_arg_reset) { return EXIT_FAILURE;
if(reset(&card, verbosity) == false) { }
return EXIT_FAILURE; printf("Successfully changed pin retries to %d and puk retries to %d.\n", args_info.pin_retries_arg, args_info.puk_retries_arg);
} } else {
printf("Successfully reset the applet.\n");
} else if(action == action_arg_pinMINUS_retries) {
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) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("Successfully changed pin retries to %d and puk retries to %d.\n", args_info.pin_retries_arg, args_info.puk_retries_arg); break;
} else { case action_arg_importMINUS_key:
return EXIT_FAILURE; 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) {
} else if(action == action_arg_importMINUS_key) { return EXIT_FAILURE;
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) { printf("Successfully imported a new private key.\n");
} else {
fprintf(stderr, "The import action needs a slot (-s) to operate on.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("Successfully imported a new private key.\n"); break;
} else { case action__NULL:
fprintf(stderr, "The import action needs a slot (-s) to operate on.\n"); default:
fprintf(stderr, "Wrong action. %d.\n", action);
return EXIT_FAILURE; return EXIT_FAILURE;
}
} }
} }