feat(ssl): X-macro driven algo list and dynamic usage
This commit is contained in:
parent
6c8bb5a3c0
commit
97d2f1383d
2 changed files with 22 additions and 7 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit f21811b66f4f5d29ada3a53bd91763cac3f6d87f
|
||||
Subproject commit 35c32a9c323046f2e8d2c0380c3e512ee5a88dd4
|
||||
|
|
@ -11,14 +11,16 @@
|
|||
|
||||
/* Forward declarations */
|
||||
static void init_config(struct ssl_config *config);
|
||||
static void print_usage(const char *prog);
|
||||
static const struct digest_algo *find_algo(const char *name);
|
||||
static enum cli_code parse_subcommand(int argc, char **argv, int first_arg,
|
||||
struct ssl_config *config);
|
||||
/* ------------------- */
|
||||
|
||||
static const struct digest_algo * const s_algos[] = {
|
||||
&g_md5,
|
||||
&g_sha256,
|
||||
#define DIGEST_ALGO(lower, ds, bs) &g_##lower,
|
||||
#include <digest_algos.h>
|
||||
#undef DIGEST_ALGO
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
@ -43,16 +45,14 @@ parse_subcommand(int argc, char **argv, int first_arg,
|
|||
if (first_arg >= argc)
|
||||
{
|
||||
fprintf(stderr, "%s: missing command\n", argv[0]);
|
||||
fprintf(stderr, "usage: %s {md5|sha256} [-pqr] [-s string] [file...]\n",
|
||||
argv[0]);
|
||||
print_usage(argv[0]);
|
||||
return CLI_ERROR;
|
||||
}
|
||||
config->algo = find_algo(argv[first_arg]);
|
||||
if (NULL == config->algo)
|
||||
{
|
||||
fprintf(stderr, "%s: unknown command -- '%s'\n", argv[0], argv[first_arg]);
|
||||
fprintf(stderr, "usage: %s {md5|sha256} [-pqr] [-s string] [file...]\n",
|
||||
argv[0]);
|
||||
print_usage(argv[0]);
|
||||
return CLI_ERROR;
|
||||
}
|
||||
config->files = argv + first_arg + 1;
|
||||
|
|
@ -73,6 +73,21 @@ find_algo(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage(const char *prog)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
fprintf(stderr, "usage: %s {", prog);
|
||||
for (i = 0; NULL != s_algos[i]; i++)
|
||||
{
|
||||
if (0 != i)
|
||||
fprintf(stderr, "|");
|
||||
fprintf(stderr, "%s", s_algos[i]->name);
|
||||
}
|
||||
fprintf(stderr, "} [-pqr] [-s string] [file...]\n");
|
||||
}
|
||||
|
||||
static void
|
||||
init_config(struct ssl_config *config)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue