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 <levitte@openssl.org>
This commit is contained in:
Rich Salz 2015-04-26 10:31:48 -04:00
parent 5d307e7b5a
commit 2f58faad66
3 changed files with 47 additions and 79 deletions

View File

@ -132,14 +132,6 @@
#define INCLUDE_FUNCTION_TABLE #define INCLUDE_FUNCTION_TABLE
#include "apps.h" #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 #ifdef OPENSSL_NO_CAMELLIA
# define FORMAT "%-15s" # define FORMAT "%-15s"
@ -161,10 +153,8 @@
DECLARE_LHASH_OF(FUNCTION); DECLARE_LHASH_OF(FUNCTION);
static LHASH_OF(FUNCTION) *prog_init(void); static LHASH_OF(FUNCTION) *prog_init(void);
static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]); static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
static int list_pkey(void); static void list_pkey(void);
static int list_cipher(void); static void list_type(FUNC_TYPE ft);
static int list_md(void);
static int list_type(FUNC_TYPE list_type);
char *default_config_file = NULL; char *default_config_file = NULL;
CONF *config = NULL; CONF *config = NULL;
@ -519,6 +509,34 @@ OPTIONS exit_options[] = {
{NULL} {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 = "<undefined>";
if (!to)
to = "<undefined>";
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 = "<undefined>";
if (!to)
to = "<undefined>";
BIO_printf((BIO *)arg, "%s => %s\n", from, to);
}
}
/* Unified enum for help and list commands. */ /* Unified enum for help and list commands. */
typedef enum HELPLIST_CHOICE { typedef enum HELPLIST_CHOICE {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
@ -558,17 +576,23 @@ int list_main(int argc, char **argv)
opt_help(list_options); opt_help(list_options);
break; break;
case OPT_COMMANDS: case OPT_COMMANDS:
return list_type(FT_general); list_type(FT_general);
break;
case OPT_DIGEST_COMMANDS: case OPT_DIGEST_COMMANDS:
return list_type(FT_md); list_type(FT_md);
break;
case OPT_DIGEST_ALGORITHMS: case OPT_DIGEST_ALGORITHMS:
return list_md(); EVP_MD_do_all_sorted(list_md_fn, bio_out);
break;
case OPT_CIPHER_COMMANDS: case OPT_CIPHER_COMMANDS:
return list_type(FT_cipher); list_type(FT_cipher);
break;
case OPT_CIPHER_ALGORITHMS: case OPT_CIPHER_ALGORITHMS:
return list_cipher(); EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
break;
case OPT_PK_ALGORITHMS: 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; return EXIT_THE_PROGRAM;
} }
static int list_type(FUNC_TYPE flist_type) static void list_type(FUNC_TYPE ft)
{ {
FUNCTION *fp; FUNCTION *fp;
int i = 0; int i = 0;
for (fp = functions; fp->name != NULL; fp++) for (fp = functions; fp->name != NULL; fp++)
if (fp->type == flist_type) { if (fp->type == ft) {
if ((i++ % COLUMNS) == 0) if ((i++ % COLUMNS) == 0)
BIO_printf(bio_out, "\n"); BIO_printf(bio_out, "\n");
BIO_printf(bio_out, FORMAT, fp->name); BIO_printf(bio_out, FORMAT, fp->name);
} }
BIO_printf(bio_out, "\n"); BIO_printf(bio_out, "\n");
return 0;
} }
static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]) 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) strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
/* Special value to mean "exit the program. */ /* Special value to mean "exit the program. */
return 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", BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
argv[0]); argv[0]);
return (1); return (1);
} }
static int list_pkey(void) static void list_pkey(void)
{ {
int i; 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 = "<undefined>";
if (!to)
to = "<undefined>";
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 = "<undefined>";
if (!to)
to = "<undefined>";
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) static int function_cmp(const FUNCTION * a, const FUNCTION * b)

View File

@ -20,7 +20,7 @@ $cmd enc -a -d < $test.cipher >$test.clear
cmp $test $test.clear || exit 1 cmp $test $test.clear || exit 1
/bin/rm $test.cipher $test.clear /bin/rm $test.cipher $test.clear
for i in `$cmd list-cipher-commands` for i in `$cmd list -cipher-commands`
do do
echo $i echo $i
$cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher

View File

@ -35,7 +35,7 @@ $ if $severity .ne. 1 then exit 3
$ delete 'test'-cipher;*,'test'-clear;* $ delete 'test'-cipher;*,'test'-clear;*
$ $
$ define/user sys$output 'test'-cipher-commands $ define/user sys$output 'test'-cipher-commands
$ 'cmd' list-cipher-commands $ 'cmd' list -cipher-commands
$ open/read f 'test'-cipher-commands $ open/read f 'test'-cipher-commands
$ loop_cipher_commands: $ loop_cipher_commands:
$ read/end=loop_cipher_commands_end f i $ read/end=loop_cipher_commands_end f i