diff --git a/tools/pkcs1-conv.c b/tools/pkcs1-conv.c index 158df5d4a43bd5c9a9c34975595c5f0ac12a852a..7a37e3e046177a5b93c8b7372e8048e0846941ff 100644 --- a/tools/pkcs1-conv.c +++ b/tools/pkcs1-conv.c @@ -42,6 +42,7 @@ enum object_type { + /* Use a range of values which also work as option id:s */ RSA_PRIVATE_KEY = 0x200, RSA_PUBLIC_KEY, DSA_PRIVATE_KEY, @@ -571,6 +572,13 @@ convert_file(struct nettle_buffer *buffer, } } +enum { + OPT_PRIVATE_RSA = RSA_PRIVATE_KEY, + OPT_PUBLIC_RSA = RSA_PUBLIC_KEY, + OPT_PRIVATE_DSA = DSA_PRIVATE_KEY, + OPT_PUBLIC_KEY = GENERAL_PUBLIC_KEY, + OPT_HELP = 0x300, +}; int main(int argc, char **argv) @@ -583,17 +591,17 @@ main(int argc, char **argv) static const struct option options[] = { /* Name, args, flag, val */ - { "help", no_argument, NULL, '?' }, + { "help", no_argument, NULL, OPT_HELP }, { "version", no_argument, NULL, 'V' }, - { "private-rsa-key", no_argument, NULL, RSA_PRIVATE_KEY }, - { "public-rsa-key", no_argument, NULL, RSA_PUBLIC_KEY }, - { "private-dsa-key", no_argument, NULL, DSA_PRIVATE_KEY }, - { "public-key-info", no_argument, NULL, GENERAL_PUBLIC_KEY }, + { "private-rsa-key", no_argument, NULL, OPT_PRIVATE_RSA }, + { "public-rsa-key", no_argument, NULL, OPT_PUBLIC_RSA }, + { "private-dsa-key", no_argument, NULL, OPT_PRIVATE_DSA }, + { "public-key-info", no_argument, NULL, OPT_PUBLIC_KEY }, { "base-64", no_argument, NULL, 'b' }, { NULL, 0, NULL, 0 } }; - while ( (c = getopt_long(argc, argv, "V?b", options, NULL)) != -1) + while ( (c = getopt_long(argc, argv, "Vb", options, NULL)) != -1) { switch (c) { @@ -604,20 +612,23 @@ main(int argc, char **argv) base64 = 1; break; - case RSA_PRIVATE_KEY: - case RSA_PUBLIC_KEY: - case DSA_PRIVATE_KEY: - case GENERAL_PUBLIC_KEY: + case OPT_PRIVATE_RSA: + case OPT_PUBLIC_RSA: + case OPT_PRIVATE_DSA: + case OPT_PUBLIC_KEY: + /* Same values as the type codes. */ type = c; break; - case '?': + case OPT_HELP: printf("FIXME: Usage information.\n"); return EXIT_SUCCESS; + case '?': + return EXIT_FAILURE; case 'V': printf("pkcs1-conv (" PACKAGE_STRING ")\n"); - exit (EXIT_SUCCESS); + return EXIT_SUCCESS; } } diff --git a/tools/sexp-conv.c b/tools/sexp-conv.c index 4b08a9cd7562b86a1d1ca11d254778aaf642c523..b0d9ef808776013bba4f54f41e587bf65945e8f3 100644 --- a/tools/sexp-conv.c +++ b/tools/sexp-conv.c @@ -216,7 +216,7 @@ struct conv_options const struct nettle_hash *hash; }; -enum { OPT_ONCE = 300, OPT_HASH, OPT_LOCK }; +enum { OPT_ONCE = 300, OPT_HASH, OPT_LOCK, OPT_HELP }; static int match_argument(const char *given, const char *name) @@ -244,7 +244,7 @@ parse_options(struct conv_options *o, static const struct option options[] = { /* Name, args, flag, val */ - { "help", no_argument, NULL, '?' }, + { "help", no_argument, NULL, OPT_HELP }, { "version", no_argument, NULL, 'V' }, { "once", no_argument, NULL, OPT_ONCE }, { "syntax", required_argument, NULL, 's' }, @@ -266,7 +266,7 @@ parse_options(struct conv_options *o, int option_index = 0; unsigned i; - c = getopt_long(argc, argv, "V?s:w:", options, &option_index); + c = getopt_long(argc, argv, "Vs:w:", options, &option_index); switch (c) { @@ -278,6 +278,9 @@ parse_options(struct conv_options *o, die("sexp-conv: Command line takes no arguments, only options.\n"); return; + case '?': + exit(EXIT_FAILURE); + case 'w': { char *end; @@ -333,7 +336,7 @@ parse_options(struct conv_options *o, o->lock = 1; break; #endif - case '?': + case OPT_HELP: printf("Usage: sexp-conv [OPTION...]\n" " Conversion: sexp-conv [OPTION...] <INPUT-SEXP\n" " Fingerprinting: sexp-conv --hash=HASH <INPUT-SEXP\n\n"