Skip to content

Commit

Permalink
Handle the cases found by unused options.
Browse files Browse the repository at this point in the history
  • Loading branch information
J08nY committed Nov 29, 2024
1 parent c84f6f5 commit 2e3b816
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/cm/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static void cm_ginit(gen_f *generators, bool prime) {
}
generators[OFFSET_ORDER] = &cm_gen_order;
} else if (cfg->method == METHOD_ANOMALOUS) {
GET(random); // Used within the method.
generators[OFFSET_FIELD] = &anomalous_gen_field;
generators[OFFSET_A] = &gen_skip;
generators[OFFSET_B] = &anomalous_gen_equation;
Expand Down Expand Up @@ -247,6 +248,7 @@ int cm_do() {
if (result) {
return result;
}
GET(count);
config_report_unused();
result = exhaustive_generate(&setup);

Expand Down
1 change: 1 addition & 0 deletions src/ecgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ int main(int argc, char *argv[]) {
}

int status;
GET(method);
if (cfg->method == METHOD_CM || cfg->method == METHOD_ANOMALOUS ||
cfg->method == METHOD_SUPERSINGULAR) {
status = cm_do();
Expand Down
1 change: 1 addition & 0 deletions src/exhaustive/exhaustive.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ int exhaustive_do() {
.check_argss = check_argss,
.unrolls = unrolls};
exhaustive_init(&setup);
GET(count);
config_report_unused();
int result = exhaustive_generate(&setup);
exhaustive_quit(&setup);
Expand Down
2 changes: 1 addition & 1 deletion src/invalid/invalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ static size_t invalid_primes(GEN order, pari_ulong **primes) {
pari_ulong upper = 0;
size_t nprimes = 0;

GET(invalid_primes);
if (cfg->invalid_primes) {
char *end = NULL;
last = (pari_ulong)strtol(cfg->invalid_primes, &end, 10) - 1;
Expand Down Expand Up @@ -353,6 +352,7 @@ int invalid_do() {
.check_argss = common_check_argss,
.unrolls = common_unrolls};
invalid_invalid_ginit(invalid_gens);
GET(invalid_primes);
config_report_unused();

debug_log_start("Starting to create curve to invalidate");
Expand Down
10 changes: 10 additions & 0 deletions src/io/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ static void cli_end(struct argp_state *state) {
"Can only generate supersingular curves over prime fields "
"currently.");
}
// Some method specific things
if (cfg->method == METHOD_SEED && cfg->seed_algo == SEED_NUMS &&
cfg->random) {
argp_failure(state, 1, 0,
"NUMS curve generation is a deterministic process.");
}
if (cfg->method == METHOD_ANOMALOUS && !cfg->random) {
argp_failure(state, 1, 0,
"Anomalous curves can only be generated randomly (specify the -r option).");
}
// default values
if (!cfg->count) {
cfg->count = 1;
Expand Down
26 changes: 26 additions & 0 deletions src/misc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>

config_t cfg_s;
config_t *cfg = &cfg_s;
Expand All @@ -15,83 +16,108 @@ config_names_t cfg_set_s = {0};
config_names_t *cfg_set = &cfg_set_s;

void config_report_unused() {
bool unused = false;
if (cfg_set->field && !cfg_used->field) {
fprintf(
stderr,
"Warning: Ignored command-line argument \"field\" (--fp/--f2m).\n");
unused = true;
}
if (cfg_set->method && !cfg_used->method) {
fprintf(stderr, "Warning: Ignored command-line argument method.\n");
unused = true;
}
if (cfg_set->count && !cfg_used->count) {
fprintf(stderr,
"Warning: Ignored command-line argument count (-c/--count).\n");
unused = true;
}
if (cfg_set->random && !cfg_used->random) {
fprintf(
stderr,
"Warning: Ignored command-line argument random (-r/--random).\n");
unused = true;
}
if (cfg_set->prime && !cfg_used->prime) {
fprintf(stderr,
"Warning: Ignored command-line argument prime (-p/--prime).\n");
unused = true;
}
if (cfg_set->cm_order && !cfg_used->cm_order) {
fprintf(
stderr,
"Warning: Ignored command-line argument cm_order (-n/--order).\n");
unused = true;
}
if (cfg_set->koblitz && !cfg_used->koblitz) {
fprintf(
stderr,
"Warning: Ignored command-line argument koblitz (-K/--koblitz).\n");
unused = true;
}
if (cfg_set->koblitz_value && !cfg_used->koblitz_value) {
fprintf(stderr,
"Warning: Ignored command-line argument koblitz_value "
"(-K/--koblitz).\n");
unused = true;
}
if (cfg_set->smooth && !cfg_used->smooth) {
fprintf(
stderr,
"Warning: Ignored command-line argument smooth (-B/--smooth).\n");
unused = true;
}
if (cfg_set->cofactor && !cfg_used->cofactor) {
fprintf(stderr,
"Warning: Ignored command-line argument cofactor "
"(-k/--cofactor).\n");
unused = true;
}
if (cfg_set->invalid_primes && !cfg_used->invalid_primes) {
fprintf(stderr,
"Warning: Ignored command-line argument invalid_primes "
"(-i/--invalid).\n");
unused = true;
}
if (cfg_set->seed_algo && !cfg_used->seed_algo) {
fprintf(
stderr,
"Warning: Ignored command-line argument seed_algo (-s/--ansi).\n");
unused = true;
}
if (cfg_set->seed && !cfg_used->seed) {
fprintf(stderr,
"Warning: Ignored command-line argument seed (-s/--ansi).\n");
unused = true;
}
if (cfg_set->unique && !cfg_used->unique) {
fprintf(
stderr,
"Warning: Ignored command-line argument unique (-u/--unique).\n");
unused = true;
}
if (cfg_set->hex_check && !cfg_used->hex_check) {
fprintf(stderr,
"Warning: Ignored command-line argument hex_check "
"(--hex-check).\n");
unused = true;
}
if (cfg_set->points && !cfg_used->points) {
fprintf(stderr,
"Warning: Ignored command-line argument points (--points).\n");
unused = true;
}
if (cfg_set->metadata && !cfg_used->metadata) {
fprintf(
stderr,
"Warning: Ignored command-line argument metadata (--metadata).\n");
unused = true;
}
#if DEBUG
if (unused) {
exit(42);
}
#else
(void)unused;
#endif
}
4 changes: 2 additions & 2 deletions test/ecgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ function brainpool() {

function nums() {
start_test
assert_raises "${ecgen} --fp -r --nums 10"
assert_raises "${ecgen} --f2m -r --nums 10" 1
assert_raises "${ecgen} --fp --nums 10"
assert_raises "${ecgen} --f2m --nums 10" 1
}

function anomalous() {
Expand Down

0 comments on commit 2e3b816

Please sign in to comment.