Skip to content
Snippets Groups Projects
Commit 2f5356bd authored by Niels Möller's avatar Niels Möller
Browse files

* tools/pkcs1-conv.c (main): Deleted short alias -? for --help,

and fixed handling of bad options.
* tools/sexp-conv.c (parse_options): Likewise.

Rev: nettle/tools/pkcs1-conv.c:1.4
Rev: nettle/tools/sexp-conv.c:1.5
parent d705d51e
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
enum object_type enum object_type
{ {
/* Use a range of values which also work as option id:s */
RSA_PRIVATE_KEY = 0x200, RSA_PRIVATE_KEY = 0x200,
RSA_PUBLIC_KEY, RSA_PUBLIC_KEY,
DSA_PRIVATE_KEY, DSA_PRIVATE_KEY,
...@@ -571,6 +572,13 @@ convert_file(struct nettle_buffer *buffer, ...@@ -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 int
main(int argc, char **argv) main(int argc, char **argv)
...@@ -583,17 +591,17 @@ main(int argc, char **argv) ...@@ -583,17 +591,17 @@ main(int argc, char **argv)
static const struct option options[] = static const struct option options[] =
{ {
/* Name, args, flag, val */ /* Name, args, flag, val */
{ "help", no_argument, NULL, '?' }, { "help", no_argument, NULL, OPT_HELP },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ "private-rsa-key", no_argument, NULL, RSA_PRIVATE_KEY }, { "private-rsa-key", no_argument, NULL, OPT_PRIVATE_RSA },
{ "public-rsa-key", no_argument, NULL, RSA_PUBLIC_KEY }, { "public-rsa-key", no_argument, NULL, OPT_PUBLIC_RSA },
{ "private-dsa-key", no_argument, NULL, DSA_PRIVATE_KEY }, { "private-dsa-key", no_argument, NULL, OPT_PRIVATE_DSA },
{ "public-key-info", no_argument, NULL, GENERAL_PUBLIC_KEY }, { "public-key-info", no_argument, NULL, OPT_PUBLIC_KEY },
{ "base-64", no_argument, NULL, 'b' }, { "base-64", no_argument, NULL, 'b' },
{ NULL, 0, NULL, 0 } { 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) switch (c)
{ {
...@@ -604,20 +612,23 @@ main(int argc, char **argv) ...@@ -604,20 +612,23 @@ main(int argc, char **argv)
base64 = 1; base64 = 1;
break; break;
case RSA_PRIVATE_KEY: case OPT_PRIVATE_RSA:
case RSA_PUBLIC_KEY: case OPT_PUBLIC_RSA:
case DSA_PRIVATE_KEY: case OPT_PRIVATE_DSA:
case GENERAL_PUBLIC_KEY: case OPT_PUBLIC_KEY:
/* Same values as the type codes. */
type = c; type = c;
break; break;
case '?': case OPT_HELP:
printf("FIXME: Usage information.\n"); printf("FIXME: Usage information.\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
case '?':
return EXIT_FAILURE;
case 'V': case 'V':
printf("pkcs1-conv (" PACKAGE_STRING ")\n"); printf("pkcs1-conv (" PACKAGE_STRING ")\n");
exit (EXIT_SUCCESS); return EXIT_SUCCESS;
} }
} }
......
...@@ -216,7 +216,7 @@ struct conv_options ...@@ -216,7 +216,7 @@ struct conv_options
const struct nettle_hash *hash; 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 static int
match_argument(const char *given, const char *name) match_argument(const char *given, const char *name)
...@@ -244,7 +244,7 @@ parse_options(struct conv_options *o, ...@@ -244,7 +244,7 @@ parse_options(struct conv_options *o,
static const struct option options[] = static const struct option options[] =
{ {
/* Name, args, flag, val */ /* Name, args, flag, val */
{ "help", no_argument, NULL, '?' }, { "help", no_argument, NULL, OPT_HELP },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ "once", no_argument, NULL, OPT_ONCE }, { "once", no_argument, NULL, OPT_ONCE },
{ "syntax", required_argument, NULL, 's' }, { "syntax", required_argument, NULL, 's' },
...@@ -266,7 +266,7 @@ parse_options(struct conv_options *o, ...@@ -266,7 +266,7 @@ parse_options(struct conv_options *o,
int option_index = 0; int option_index = 0;
unsigned i; 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) switch (c)
{ {
...@@ -278,6 +278,9 @@ parse_options(struct conv_options *o, ...@@ -278,6 +278,9 @@ parse_options(struct conv_options *o,
die("sexp-conv: Command line takes no arguments, only options.\n"); die("sexp-conv: Command line takes no arguments, only options.\n");
return; return;
case '?':
exit(EXIT_FAILURE);
case 'w': case 'w':
{ {
char *end; char *end;
...@@ -333,7 +336,7 @@ parse_options(struct conv_options *o, ...@@ -333,7 +336,7 @@ parse_options(struct conv_options *o,
o->lock = 1; o->lock = 1;
break; break;
#endif #endif
case '?': case OPT_HELP:
printf("Usage: sexp-conv [OPTION...]\n" printf("Usage: sexp-conv [OPTION...]\n"
" Conversion: sexp-conv [OPTION...] <INPUT-SEXP\n" " Conversion: sexp-conv [OPTION...] <INPUT-SEXP\n"
" Fingerprinting: sexp-conv --hash=HASH <INPUT-SEXP\n\n" " Fingerprinting: sexp-conv --hash=HASH <INPUT-SEXP\n\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment