=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/openssl/pkeyparam.c,v retrieving revision 1.3 retrieving revision 1.4 diff -c -r1.3 -r1.4 *** src/usr.bin/openssl/pkeyparam.c 2014/08/28 14:25:48 1.3 --- src/usr.bin/openssl/pkeyparam.c 2015/04/11 15:21:42 1.4 *************** *** 1,4 **** ! /* $OpenBSD: pkeyparam.c,v 1.3 2014/08/28 14:25:48 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006 */ --- 1,4 ---- ! /* $OpenBSD: pkeyparam.c,v 1.4 2015/04/11 15:21:42 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006 */ *************** *** 65,147 **** #include #include int pkeyparam_main(int, char **); int pkeyparam_main(int argc, char **argv) { - char **args, *infile = NULL, *outfile = NULL; BIO *in = NULL, *out = NULL; - int text = 0, noout = 0; EVP_PKEY *pkey = NULL; - int badarg = 0; - #ifndef OPENSSL_NO_ENGINE - char *engine = NULL; - #endif int ret = 1; ! args = argv + 1; ! while (!badarg && *args && *args[0] == '-') { ! if (!strcmp(*args, "-in")) { ! if (args[1]) { ! args++; ! infile = *args; ! } else ! badarg = 1; ! } else if (!strcmp(*args, "-out")) { ! if (args[1]) { ! args++; ! outfile = *args; ! } else ! badarg = 1; ! } ! #ifndef OPENSSL_NO_ENGINE ! else if (strcmp(*args, "-engine") == 0) { ! if (!args[1]) ! goto bad; ! engine = *(++args); ! } ! #endif ! else if (strcmp(*args, "-text") == 0) ! text = 1; ! else if (strcmp(*args, "-noout") == 0) ! noout = 1; ! args++; } - if (badarg) { #ifndef OPENSSL_NO_ENGINE ! bad: #endif - BIO_printf(bio_err, "Usage pkeyparam [options]\n"); - BIO_printf(bio_err, "where options are\n"); - BIO_printf(bio_err, "-in file input file\n"); - BIO_printf(bio_err, "-out file output file\n"); - BIO_printf(bio_err, "-text print parameters as text\n"); - BIO_printf(bio_err, "-noout don't output encoded parameters\n"); - #ifndef OPENSSL_NO_ENGINE - BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n"); - #endif - return 1; - } - #ifndef OPENSSL_NO_ENGINE - setup_engine(bio_err, engine, 0); - #endif ! if (infile) { ! if (!(in = BIO_new_file(infile, "r"))) { ! BIO_printf(bio_err, ! "Can't open input file %s\n", infile); ! goto end; } } else in = BIO_new_fp(stdin, BIO_NOCLOSE); ! if (outfile) { ! if (!(out = BIO_new_file(outfile, "w"))) { ! BIO_printf(bio_err, ! "Can't open output file %s\n", outfile); goto end; } } else { --- 65,160 ---- #include #include + struct { + #ifndef OPENSSL_NO_ENGINE + char *engine; + #endif + char *infile; + int noout; + char *outfile; + int text; + } pkeyparam_config; + + struct option pkeyparam_options[] = { + #ifndef OPENSSL_NO_ENGINE + { + .name = "engine", + .argname = "id", + .desc = "Use the engine specified by the given identifier", + .type = OPTION_ARG, + .opt.arg = &pkeyparam_config.engine, + }, + #endif + { + .name = "in", + .argname = "file", + .desc = "Input file (default stdin)", + .type = OPTION_ARG, + .opt.arg = &pkeyparam_config.infile, + }, + { + .name = "noout", + .desc = "Do not print encoded version of the parameters", + .type = OPTION_FLAG, + .opt.flag = &pkeyparam_config.noout, + }, + { + .name = "out", + .argname = "file", + .desc = "Output file (default stdout)", + .type = OPTION_ARG, + .opt.arg = &pkeyparam_config.outfile, + }, + { + .name = "text", + .desc = "Print out the parameters in plain text", + .type = OPTION_FLAG, + .opt.flag = &pkeyparam_config.text, + }, + { NULL }, + }; + + static void + pkeyparam_usage() + { + fprintf(stderr, + "usage: pkeyparam [-engine id] [-in file] [-noout] [-out file] " + "[-text]\n"); + options_usage(pkeyparam_options); + } + int pkeyparam_main(int, char **); int pkeyparam_main(int argc, char **argv) { BIO *in = NULL, *out = NULL; EVP_PKEY *pkey = NULL; int ret = 1; ! memset(&pkeyparam_config, 0, sizeof(pkeyparam_config)); ! if (options_parse(argc, argv, pkeyparam_options, NULL, NULL) != 0) { ! pkeyparam_usage(); ! return (1); } #ifndef OPENSSL_NO_ENGINE ! setup_engine(bio_err, pkeyparam_config.engine, 0); #endif ! if (pkeyparam_config.infile) { ! if (!(in = BIO_new_file(pkeyparam_config.infile, "r"))) { ! BIO_printf(bio_err, "Can't open input file %s\n", ! pkeyparam_config.infile); } } else in = BIO_new_fp(stdin, BIO_NOCLOSE); ! if (pkeyparam_config.outfile) { ! if (!(out = BIO_new_file(pkeyparam_config.outfile, "w"))) { ! BIO_printf(bio_err, "Can't open output file %s\n", ! pkeyparam_config.outfile); goto end; } } else { *************** *** 154,163 **** ERR_print_errors(bio_err); goto end; } ! if (!noout) PEM_write_bio_Parameters(out, pkey); ! if (text) EVP_PKEY_print_params(out, pkey, 0, NULL); ret = 0; --- 167,176 ---- ERR_print_errors(bio_err); goto end; } ! if (!pkeyparam_config.noout) PEM_write_bio_Parameters(out, pkey); ! if (pkeyparam_config.text) EVP_PKEY_print_params(out, pkey, 0, NULL); ret = 0;