/* See LICENSE file for copyright and license details. */
#include "common.h"
static enum command command = ANYSUM;
static enum libhashsum_algorithm algorithm;
#define USAGE_COMMON "[-c [-w]] [-W options] ... [-z] [file] ..."
#define USAGE_BSUM "[-l bits] [-S salt] "USAGE_COMMON
#define USAGE_SHA3SUM "[-a bits] "USAGE_COMMON
#define USAGE_KECCAK "[-R rate] [-C capacity] [-N output-size] [-S state-size] [-W word-size] [-Z squeeze-count] "USAGE_COMMON
#define USAGE_SHAKE "[-N output-bits] "USAGE_COMMON
#define USAGE_RAWSHAKE "[-N output-bits] "USAGE_COMMON
#define USAGE_ANYSUM "(-c [-w] | [-a algoritms] ... ) [-W options] ... [-z] [file] ..."
#define static
NUSAGE(libsimple_default_failure_exit,
(command == ANYSUM ? USAGE_ANYSUM :
command == BSUM ? USAGE_BSUM :
command == SHA3SUM ? USAGE_SHA3SUM :
(algorithm == LIBHASHSUM_BLAKE224 ||
algorithm == LIBHASHSUM_BLAKE256 ||
algorithm == LIBHASHSUM_BLAKE384 ||
algorithm == LIBHASHSUM_BLAKE512) ? USAGE_BSUM :
(algorithm == LIBHASHSUM_SHAKE128 ||
algorithm == LIBHASHSUM_SHAKE256 ||
algorithm == LIBHASHSUM_SHAKE512) ? USAGE_SHAKE :
(algorithm == LIBHASHSUM_RAWSHAKE128 ||
algorithm == LIBHASHSUM_RAWSHAKE256 ||
algorithm == LIBHASHSUM_RAWSHAKE512) ? USAGE_RAWSHAKE :
algorithm == LIBHASHSUM_KECCAK ? USAGE_KECCAK : USAGE_COMMON));
#undef static
void
cmdline(int *argcp, char ***argvp, struct config *config, char **algostrbufp)
{
int old_argc = *argcp;
int argc = *argcp;
char **argv = *argvp;
const char *algostr = NULL;
argv0 = argv[0];
command = getcommand(&algostr, &algorithm);
switch (getsupercommand(command, algorithm)) {
case BSUM:
argc = cmdline_bsum(argc, argv, command, config, &algostr, &algorithm, algostrbufp);
break;
case SHA3SUM:
argc = cmdline_sha3sum(argc, argv, command, config, &algostr, &algorithm, algostrbufp);
break;
case ANYSUM:
case SPECIALISED:
default:
argc = cmdline_other(argc, argv, command, config);
break;
}
if (config->warn_improper_format > config->verify)
usage();
if (command == ANYSUM) {
if (config->verify && config->nalgorithms)
usage();
config->format |= WITH_ALGOSTR;
}
if (!config->verify) {
if ((config->format & FORMAT_MASK) == BINARY)
config->format &= FORMAT_MASK;
}
if (algostr) {
config->algorithms = erealloc(config->algorithms, sizeof(*config->algorithms));
memset(&(config->algorithms)[0], 0, sizeof(config->algorithms[0]));
(config->algorithms)[0].algostr = algostr;
(config->algorithms)[0].result = NULL;
config->nalgorithms = 1U;
}
*argcp = argc;
*argvp = &argv[old_argc - argc];
}