diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-28 16:42:05 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-28 16:42:05 +0200 |
commit | a24071ae913b223487df78859c8d830f9e69f580 (patch) | |
tree | e2ec712cc29461c82cfdd477e8b1ba961b50018d /cmdline.c | |
parent | First commit (diff) | |
download | anysum-a24071ae913b223487df78859c8d830f9e69f580.tar.gz anysum-a24071ae913b223487df78859c8d830f9e69f580.tar.bz2 anysum-a24071ae913b223487df78859c8d830f9e69f580.tar.xz |
Second commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | cmdline.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/cmdline.c b/cmdline.c new file mode 100644 index 0000000..182a29d --- /dev/null +++ b/cmdline.c @@ -0,0 +1,84 @@ +/* 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) +{ + int old_argc = *argcp; + int argc = *argcp; + char **argv = *argvp; + const char *algostr = NULL; + char *algostrbuf = NULL; + + argv0 = argv[0]; + command = getcommand(&algostr, &algorithm); + switch (getsupercommand(command, algorithm)) { + case BSUM: + argc = cmdline_bsum(argc, argv, command, config, &algostr, &algorithm, &algostrbuf); + break; + case SHA3SUM: + argc = cmdline_sha3sum(argc, argv, command, config, &algostr, &algorithm, &algostrbuf); + 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)); + (config->algorithms)[0].algostr = algostr; + config->nalgorithms = 1U; + } + + *argcp = argc; + *argvp = &argv[old_argc - argc]; + + free(algostrbuf); +} |