diff options
| author | J08nY | 2018-07-12 15:01:38 +0200 |
|---|---|---|
| committer | J08nY | 2018-07-12 15:01:38 +0200 |
| commit | 35d80e26ca2284e20ee93eb5bf05914f73fca6d3 (patch) | |
| tree | a4b0387b523a6866b38658dbfa7c55f4dd9732d9 /src/io/cli.c | |
| parent | e73dbb321629b845d37cae1b8376a8ac5a7542be (diff) | |
| download | ecgen-35d80e26ca2284e20ee93eb5bf05914f73fca6d3.tar.gz ecgen-35d80e26ca2284e20ee93eb5bf05914f73fca6d3.tar.zst ecgen-35d80e26ca2284e20ee93eb5bf05914f73fca6d3.zip | |
Diffstat (limited to 'src/io/cli.c')
| -rw-r--r-- | src/io/cli.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/io/cli.c b/src/io/cli.c index 940de84..de1fd12 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -3,10 +3,10 @@ * Copyright (C) 2017-2018 J08nY */ #include "cli.h" +#include <regex.h> #include <string.h> #include "exhaustive/ansi.h" #include "exhaustive/brainpool.h" -#include "misc/config.h" char cli_doc[] = "ecgen, tool for generating Elliptic curve domain parameters.\v(C) " @@ -90,6 +90,24 @@ struct argp_option cli_options[] = { }; // clang-format on +static regex_t re_cm_order; + +bool cli_init() { + int error = regcomp( + &re_cm_order, + "((0[xX][0-9a-fA-F]+)|([0-9]+))(,((0[xX][0-9a-fA-F]+)|([0-9]+)))*", + REG_EXTENDED); + if (error) { + size_t length = regerror(error, &re_cm_order, NULL, 0); + char msg[length + 1]; + regerror(error, &re_cm_order, msg, length + 1); + fprintf(stderr, "Error compiling regex: %s\n", msg); + return false; + } + + return true; +} + static unsigned long cli_parse_memory(const char *str, struct argp_state *state) { char *suffix = NULL; @@ -184,7 +202,7 @@ static void cli_end(struct argp_state *state) { error_t cli_parse(int key, char *arg, struct argp_state *state) { switch (key) { - /* Field options */ + /* Field options */ case OPT_FP: cfg->field |= FIELD_PRIME; break; @@ -206,6 +224,10 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { case OPT_ORDER: cfg->method |= METHOD_CM; if (arg) { + int error = regexec(&re_cm_order, arg, 0, NULL, 0); + if (error != 0) { + argp_failure(state, 1, 0, "Invalid order %s", arg); + } cfg->cm_order = arg; } break; @@ -418,3 +440,5 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { char *cli_filter(int key, const char *text, void *input) { return (char *)text; } + +void cli_quit() { regfree(&re_cm_order); }
\ No newline at end of file |
