From: Mark Wooding Date: Sun, 20 Oct 2019 22:18:09 +0000 (+0100) Subject: *.c: Split the constant definitions into the various submodules. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/810542b01716cfd7017315c25a165ebfbe45afe5?hp=c263b05cca879ab1bdca5823df0413604d39d4c6 *.c: Split the constant definitions into the various submodules. --- diff --git a/algorithms.c b/algorithms.c index 0ff2bf0..f792087 100644 --- a/algorithms.c +++ b/algorithms.c @@ -3558,6 +3558,12 @@ static const PyTypeObject gprp_pytype_skel = { /*----- Main code ---------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(AEADF_PCHSZ), CONST(AEADF_PCMSZ), CONST(AEADF_PCTSZ), + CONST(AEADF_AADNDEP), CONST(AEADF_AADFIRST), CONST(AEADF_NOAAD), + { 0 } +}; + static const PyMethodDef methods[] = { #define METHNAME(func) meth_##func #define METH_HDANCE(hdance, HDance) METH(hdance##_prf, \ @@ -3651,6 +3657,7 @@ void algorithms_pyinsert(PyObject *mod) INSERT("GCPRP", gcprp_pytype); INSERT("GPRP", gprp_pytype); INSERT("gcprps", gcprps()); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/catacomb.c b/catacomb.c index 62889c2..60dae45 100644 --- a/catacomb.c +++ b/catacomb.c @@ -30,38 +30,6 @@ /*----- Main code ---------------------------------------------------------*/ -static const struct nameval consts[] = { -#define CF(f, x) { #x, f, x } -#define C(x) { #x, (x) >= 0 ? 0 : CF_SIGNED, x } - C(FTY_PRIME), C(FTY_BINARY), - C(PGEN_PASS), C(PGEN_FAIL), C(PGEN_BEGIN), C(PGEN_TRY), C(PGEN_DONE), - C(PGEN_ABORT), - C(MPW_MAX), - C(RAND_IBITS), - C(PMODE_READ), C(PMODE_VERIFY), - C(KOPEN_READ), C(KOPEN_WRITE), C(KOPEN_NOFILE), - CF(0, KEXP_FOREVER), CF(0, KEXP_EXPIRE), - C(KF_ENCMASK), C(KENC_BINARY), C(KENC_MP), C(KENC_STRUCT), - C(KENC_ENCRYPT), C(KENC_STRING), C(KENC_EC), - C(KF_CATMASK), C(KCAT_SYMM), C(KCAT_PRIV), C(KCAT_PUB), C(KCAT_SHARE), - C(KF_NONSECRET), - C(KF_BURN), C(KF_OPT), - C(EC_XONLY), C(EC_YBIT), C(EC_LSB), C(EC_CMPR), C(EC_EXPLY), C(EC_SORT), - C(X25519_KEYSZ), C(X25519_PUBSZ), C(X25519_OUTSZ), - C(X448_KEYSZ), C(X448_PUBSZ), C(X448_OUTSZ), - C(ED25519_KEYSZ), C(ED25519_PUBSZ), C(ED25519_SIGSZ), - C(ED25519_MAXPERSOSZ), - C(ED448_KEYSZ), C(ED448_PUBSZ), C(ED448_SIGSZ), C(ED448_MAXPERSOSZ), - C(AEADF_PCHSZ), C(AEADF_PCMSZ), C(AEADF_PCTSZ), - C(AEADF_AADNDEP), C(AEADF_AADFIRST), C(AEADF_NOAAD), -#define ENTRY(tag, val, str) C(KERR_##tag), - KEY_ERRORS(ENTRY) -#undef ENTRY -#undef C -#undef CF - { 0 } -}; - PyObject *mexp_common(PyObject *me, PyObject *arg, size_t efsz, PyObject *(*id)(PyObject *), @@ -195,7 +163,6 @@ EXPORT void init_base(void) mod = Py_InitModule("catacomb._base", donemethods()); INSERT_MODULES; INSERT("smallprimes", smallprimes()); - setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/ec.c b/ec.c index 26cadb6..ec4a98d 100644 --- a/ec.c +++ b/ec.c @@ -1543,6 +1543,12 @@ static const PyTypeObject ecinfo_pytype_skel = { /*----- Setup -------------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(EC_XONLY), CONST(EC_YBIT), CONST(EC_LSB), + CONST(EC_CMPR), CONST(EC_EXPLY), CONST(EC_SORT), + { 0 } +}; + void ec_pyinit(void) { INITTYPE(ecpt, root); @@ -1591,6 +1597,7 @@ void ec_pyinsert(PyObject *mod) INSERT("ECBinProjCurve", ecbinprojcurve_pytype); INSERT("ECInfo", ecinfo_pytype); INSERT("_eccurves", namedcurves()); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/field.c b/field.c index 9da6063..ba7badb 100644 --- a/field.c +++ b/field.c @@ -943,6 +943,11 @@ static const PyTypeObject binnormfield_pytype_skel = { /*----- Setup -------------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(FTY_PRIME), CONST(FTY_BINARY), + { 0 } +}; + void field_pyinit(void) { INITTYPE(fe, root); @@ -963,6 +968,7 @@ void field_pyinsert(PyObject *mod) INSERT("BinField", binfield_pytype); INSERT("BinPolyField", binpolyfield_pytype); INSERT("BinNormField", binnormfield_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/key.c b/key.c index 919b8f9..90ff334 100644 --- a/key.c +++ b/key.c @@ -2060,6 +2060,21 @@ static const PyTypeObject keyfile_pytype_skel = { /*----- Initialization ----------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(KOPEN_READ), CONST(KOPEN_WRITE), CONST(KOPEN_NOFILE), + CONSTFLAG(0, KEXP_FOREVER), CONSTFLAG(0, KEXP_EXPIRE), + CONST(KF_ENCMASK), CONST(KENC_BINARY), CONST(KENC_MP), CONST(KENC_STRUCT), + CONST(KENC_ENCRYPT), CONST(KENC_STRING), CONST(KENC_EC), + CONST(KF_CATMASK), CONST(KCAT_SYMM), CONST(KCAT_PRIV), CONST(KCAT_PUB), + CONST(KCAT_SHARE), + CONST(KF_NONSECRET), + CONST(KF_BURN), CONST(KF_OPT), +#define ENTRY(tag, val, str) CONST(KERR_##tag), + KEY_ERRORS(ENTRY) +#undef ENTRY + { 0 } +}; + void key_pyinit(void) { INITTYPE(keyfile, root); @@ -2095,6 +2110,7 @@ void key_pyinsert(PyObject *mod) INSERT("KeyDataString", keydatastr_pytype); INSERT("KeyDataStructured", keydatastruct_pytype); INSERT("SubKeyIter", subkeyiter_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/mp.c b/mp.c index fbafcee..2f8594d 100644 --- a/mp.c +++ b/mp.c @@ -2504,6 +2504,11 @@ static const PyTypeObject gfn_pytype_skel = { /*----- Glue --------------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(MPW_MAX), + { 0 } +}; + void mp_pyinit(void) { INITTYPE(mp, root); @@ -2528,6 +2533,7 @@ void mp_pyinsert(PyObject *mod) INSERT("GF", gf_pytype); INSERT("GFReduce", gfreduce_pytype); INSERT("GFN", gfn_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/passphrase.c b/passphrase.c index 25d448b..6720d65 100644 --- a/passphrase.c +++ b/passphrase.c @@ -177,6 +177,11 @@ static const PyTypeObject pixie_pytype_skel = { /*----- Main code ---------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(PMODE_READ), CONST(PMODE_VERIFY), + { 0 } +}; + static PyObject *meth_ppread(PyObject *me, PyObject *arg, PyObject *kw) { char *tag; @@ -238,6 +243,7 @@ void passphrase_pyinit(void) void passphrase_pyinsert(PyObject *mod) { INSERT("Pixie", pixie_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/pgen.c b/pgen.c index 6bbfd82..291d289 100644 --- a/pgen.c +++ b/pgen.c @@ -1051,6 +1051,12 @@ end: /*----- Global stuff ------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(PGEN_PASS), CONST(PGEN_FAIL), CONST(PGEN_BEGIN), CONST(PGEN_TRY), + CONST(PGEN_DONE), CONST(PGEN_ABORT), + { 0 } +}; + static const PyMethodDef methods[] = { #define METHNAME(name) meth_##name KWMETH(pgen, @@ -1098,6 +1104,7 @@ void pgen_pyinsert(PyObject *mod) INSERT("pgen_stdev", pgev_stdev(pgen_ev)); INSERT("pgen_spinev", pgev_stdev(pgen_evspin)); INSERT("pgen_subev", pgev_stdev(pgen_subev)); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/pubkey.c b/pubkey.c index 05fc397..b1d32a5 100644 --- a/pubkey.c +++ b/pubkey.c @@ -1256,6 +1256,16 @@ EDDSAS(DEFEDDSA) /*----- Global stuff ------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(X25519_KEYSZ), CONST(X25519_PUBSZ), CONST(X25519_OUTSZ), + CONST(X448_KEYSZ), CONST(X448_PUBSZ), CONST(X448_OUTSZ), + CONST(ED25519_KEYSZ), CONST(ED25519_PUBSZ), CONST(ED25519_SIGSZ), + CONST(ED25519_MAXPERSOSZ), + CONST(ED448_KEYSZ), CONST(ED448_PUBSZ), CONST(ED448_SIGSZ), + CONST(ED448_MAXPERSOSZ), + { 0 } +}; + static const PyMethodDef methods[] = { #define METHNAME(name) meth_##name KWMETH(_p1crypt_encode, 0) @@ -1301,6 +1311,7 @@ void pubkey_pyinsert(PyObject *mod) INSERT("KCDSAPriv", kcdsapriv_pytype); INSERT("RSAPub", rsapub_pytype); INSERT("RSAPriv", rsapriv_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/pyke/pyke.h b/pyke/pyke.h index 138a9fb..64608d9 100644 --- a/pyke/pyke.h +++ b/pyke/pyke.h @@ -321,6 +321,8 @@ extern PyObject *mkexc(PyObject */*mod*/, PyObject */*base*/, struct nameval { const char *name; unsigned f; unsigned long value; }; #define CF_SIGNED 1u extern void setconstants(PyObject *, const struct nameval *); +#define CONST(x) { #x, (x) >= 0 ? 0 : CF_SIGNED, x } +#define CONSTFLAG(f, x) { #x, f, x } #define INSEXC(name, var, base, meth) \ INSERT(name, var = mkexc(mod, base, name, meth)) diff --git a/rand.c b/rand.c index 96a86d5..2c99f26 100644 --- a/rand.c +++ b/rand.c @@ -1489,6 +1489,11 @@ static const PyTypeObject bbspriv_pytype_skel = { /*----- Global stuff ------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(RAND_IBITS), + { 0 } +}; + void rand_pyinit(void) { INITTYPE(grand, root); @@ -1530,6 +1535,7 @@ void rand_pyinsert(PyObject *mod) gccrands_dict = gccrands(); Py_INCREF(gccrands_dict); INSERT("gccrands", gccrands_dict); INSERT("rand", rand_pyobj); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/