diff --git a/test/testcrypt.py b/test/testcrypt.py index d21f19c7..b71f851d 100644 --- a/test/testcrypt.py +++ b/test/testcrypt.py @@ -103,6 +103,8 @@ method_prefixes = { } method_lists = {t: [] for t in method_prefixes} +checked_enum_values = {} + class Value(object): def __init__(self, typename, ident): self._typename = typename @@ -182,7 +184,13 @@ def make_argword(arg, argtype, fnname, argindex, argname, to_preserve): "argon2flavour", "fptype", "httpdigesthash"}: arg = coerce_to_bytes(arg) if isinstance(arg, bytes) and b" " not in arg: - return arg + dictkey = (typename, arg) + if dictkey not in checked_enum_values: + retwords = childprocess.funcall("checkenum", [typename, arg]) + assert len(retwords) == 1 + checked_enum_values[dictkey] = (retwords[0] == b"ok") + if checked_enum_values[dictkey]: + return arg if typename == "mpint_list": sublist = [make_argword(len(arg), ("uint", False), fnname, argindex, argname, to_preserve)] diff --git a/testcrypt.c b/testcrypt.c index f6cb8517..68e2d11d 100644 --- a/testcrypt.c +++ b/testcrypt.c @@ -623,6 +623,25 @@ static void handle_mp_dump(BinarySource *in, strbuf *out) put_byte(out, '\n'); } +static void handle_checkenum(BinarySource *in, strbuf *out) +{ + ptrlen type = get_word(in); + ptrlen value = get_word(in); + bool ok = false; + + #define BEGIN_ENUM_TYPE(name) \ + if (ptrlen_eq_string(type, #name)) \ + ok = enum_translate_##name(value, NULL); + #define ENUM_VALUE(name, value) + #define END_ENUM_TYPE(name) + #include "testcrypt-enum.h" + #undef BEGIN_ENUM_TYPE + #undef ENUM_VALUE + #undef END_ENUM_TYPE + + put_dataz(out, ok ? "ok\n" : "bad\n"); +} + static void random_queue(ptrlen pl) { bufchain_add(&random_data_queue, pl.ptr, pl.len); @@ -1356,6 +1375,7 @@ static void process_line(BinarySource *in, strbuf *out) DISPATCH_COMMAND(getstring); DISPATCH_COMMAND(mp_literal); DISPATCH_COMMAND(mp_dump); + DISPATCH_COMMAND(checkenum); #undef DISPATCH_COMMAND #define FUNC_INNER(outtype, fname, realname, args) \