From 2f58faad668ee1b4270611d6548c9fbe78589fe6 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Sun, 26 Apr 2015 10:31:48 -0400 Subject: [PATCH] Remove the special list-xxxx commands There's a new "list" command, which takes a flag to say what to list. Removing the old hacky commands. Re-ordered some functions to remove some needless declarations. Reviewed-by: Richard Levitte --- apps/openssl.c | 122 +++++++++++++++++------------------------------ test/testenc | 2 +- test/testenc.com | 2 +- 3 files changed, 47 insertions(+), 79 deletions(-) diff --git a/apps/openssl.c b/apps/openssl.c index de73fac7a9..2a85145c91 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -132,14 +132,6 @@ #define INCLUDE_FUNCTION_TABLE #include "apps.h" -#if 1 -# define LIST_STANDARD_COMMANDS "list-standard-commands" -# define LIST_MESSAGE_DIGEST_COMMANDS "list-message-digest-commands" -# define LIST_MESSAGE_DIGEST_ALGORITHMS "list-message-digest-algorithms" -# define LIST_CIPHER_COMMANDS "list-cipher-commands" -# define LIST_CIPHER_ALGORITHMS "list-cipher-algorithms" -# define LIST_PUBLIC_KEY_ALGORITHMS "list-public-key-algorithms" -#endif #ifdef OPENSSL_NO_CAMELLIA # define FORMAT "%-15s" @@ -161,10 +153,8 @@ DECLARE_LHASH_OF(FUNCTION); static LHASH_OF(FUNCTION) *prog_init(void); static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]); -static int list_pkey(void); -static int list_cipher(void); -static int list_md(void); -static int list_type(FUNC_TYPE list_type); +static void list_pkey(void); +static void list_type(FUNC_TYPE ft); char *default_config_file = NULL; CONF *config = NULL; @@ -519,6 +509,34 @@ OPTIONS exit_options[] = { {NULL} }; +static void list_cipher_fn(const EVP_CIPHER *c, + const char *from, const char *to, void *arg) +{ + if (c) + BIO_printf(arg, "%s\n", EVP_CIPHER_name(c)); + else { + if (!from) + from = ""; + if (!to) + to = ""; + BIO_printf(arg, "%s => %s\n", from, to); + } +} + +static void list_md_fn(const EVP_MD *m, + const char *from, const char *to, void *arg) +{ + if (m) + BIO_printf(arg, "%s\n", EVP_MD_name(m)); + else { + if (!from) + from = ""; + if (!to) + to = ""; + BIO_printf((BIO *)arg, "%s => %s\n", from, to); + } +} + /* Unified enum for help and list commands. */ typedef enum HELPLIST_CHOICE { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, @@ -558,17 +576,23 @@ int list_main(int argc, char **argv) opt_help(list_options); break; case OPT_COMMANDS: - return list_type(FT_general); + list_type(FT_general); + break; case OPT_DIGEST_COMMANDS: - return list_type(FT_md); + list_type(FT_md); + break; case OPT_DIGEST_ALGORITHMS: - return list_md(); + EVP_MD_do_all_sorted(list_md_fn, bio_out); + break; case OPT_CIPHER_COMMANDS: - return list_type(FT_cipher); + list_type(FT_cipher); + break; case OPT_CIPHER_ALGORITHMS: - return list_cipher(); + EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out); + break; case OPT_PK_ALGORITHMS: - return list_pkey(); + list_pkey(); + break; } } @@ -641,19 +665,18 @@ int exit_main(int argc, char **argv) return EXIT_THE_PROGRAM; } -static int list_type(FUNC_TYPE flist_type) +static void list_type(FUNC_TYPE ft) { FUNCTION *fp; int i = 0; for (fp = functions; fp->name != NULL; fp++) - if (fp->type == flist_type) { + if (fp->type == ft) { if ((i++ % COLUMNS) == 0) BIO_printf(bio_out, "\n"); BIO_printf(bio_out, FORMAT, fp->name); } BIO_printf(bio_out, "\n"); - return 0; } static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]) @@ -695,27 +718,13 @@ static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]) strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0) /* Special value to mean "exit the program. */ return EXIT_THE_PROGRAM; -#ifdef LIST_STANDARD_COMMANDS - if (strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) - return list_type(FT_general); - if (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) - return list_md(); - if (strcmp(argv[0], LIST_PUBLIC_KEY_ALGORITHMS) == 0) - return list_pkey(); - if (strcmp(argv[0], LIST_CIPHER_ALGORITHMS) == 0) - return list_cipher(); - if (strcmp(argv[0], LIST_CIPHER_COMMANDS) == 0) - return list_type(FT_cipher); - if (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) - return list_type(FT_md); -#endif BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n", argv[0]); return (1); } -static int list_pkey(void) +static void list_pkey(void) { int i; @@ -742,47 +751,6 @@ static int list_pkey(void) } } - return 0; -} - -static void list_cipher_fn(const EVP_CIPHER *c, - const char *from, const char *to, void *arg) -{ - if (c) - BIO_printf(arg, "%s\n", EVP_CIPHER_name(c)); - else { - if (!from) - from = ""; - if (!to) - to = ""; - BIO_printf(arg, "%s => %s\n", from, to); - } -} - -static int list_cipher(void) -{ - EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out); - return 0; -} - -static void list_md_fn(const EVP_MD *m, - const char *from, const char *to, void *arg) -{ - if (m) - BIO_printf(arg, "%s\n", EVP_MD_name(m)); - else { - if (!from) - from = ""; - if (!to) - to = ""; - BIO_printf((BIO *)arg, "%s => %s\n", from, to); - } -} - -static int list_md(void) -{ - EVP_MD_do_all_sorted(list_md_fn, bio_out); - return 0; } static int function_cmp(const FUNCTION * a, const FUNCTION * b) diff --git a/test/testenc b/test/testenc index 3a07398eab..87b70ec111 100644 --- a/test/testenc +++ b/test/testenc @@ -20,7 +20,7 @@ $cmd enc -a -d < $test.cipher >$test.clear cmp $test $test.clear || exit 1 /bin/rm $test.cipher $test.clear -for i in `$cmd list-cipher-commands` +for i in `$cmd list -cipher-commands` do echo $i $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher diff --git a/test/testenc.com b/test/testenc.com index 75acd6f07f..fcd66399d6 100644 --- a/test/testenc.com +++ b/test/testenc.com @@ -35,7 +35,7 @@ $ if $severity .ne. 1 then exit 3 $ delete 'test'-cipher;*,'test'-clear;* $ $ define/user sys$output 'test'-cipher-commands -$ 'cmd' list-cipher-commands +$ 'cmd' list -cipher-commands $ open/read f 'test'-cipher-commands $ loop_cipher_commands: $ read/end=loop_cipher_commands_end f i -- 2.25.1