addmethods(methods);
}
-GEN(gcciphers, cipher)
-GEN(gcaeads, aead)
-GEN(gchashes, hash)
-GEN(gcmacs, mac)
#define gcprp prpinfo
-GEN(gcprps, prp)
+#define CLASS_TABLES(_) _(cipher) _(aead) _(hash) _(mac) _(prp)
+#define TABLE_FNS(pre) \
+ static const char *pre##_namefn(const void *p) \
+ { const gc##pre *const *cls = p; return (*cls ? (*cls)->name : 0); } \
+ static PyObject *pre##_valfn(const void *p) \
+ { gc##pre *const*cls = p; return (gc##pre##_pywrap(*cls)); }
+CLASS_TABLES(TABLE_FNS)
void algorithms_pyinsert(PyObject *mod)
{
INSERT("KeySZSet", keyszset_pytype);
INSERT("GCCipher", gccipher_pytype);
INSERT("GCipher", gcipher_pytype);
- INSERT("gcciphers", gcciphers());
+ INSERT("gcciphers", make_algtab(gciphertab, sizeof(gccipher *),
+ cipher_namefn, cipher_valfn));
INSERT("GCAEAD", gcaead_pytype);
INSERT("GAEKey", gaeadkey_pytype);
INSERT("GAEAADClass", gcaeadaad_pytype);
INSERT("GAEEnc", gaeadenc_pytype);
INSERT("GAEDecClass", gcaeaddec_pytype);
INSERT("GAEDec", gaeaddec_pytype);
- INSERT("gcaeads", gcaeads());
+ INSERT("gcaeads", make_algtab(gaeadtab, sizeof(gcaead *),
+ aead_namefn, aead_valfn));
INSERT("GCHash", gchash_pytype);
INSERT("GHash", ghash_pytype);
- INSERT("gchashes", d = gchashes());
- sha_pyobj = PyDict_GetItemString(d, "sha"); Py_INCREF(sha_pyobj);
- has160_pyobj = PyDict_GetItemString(d, "has160"); Py_INCREF(has160_pyobj);
+ d = make_algtab(ghashtab, sizeof(gchash *), hash_namefn, hash_valfn);
+ INSERT("gchashes", d);
+ sha_pyobj = PyMapping_GetItemString(d, "sha"); Py_INCREF(sha_pyobj);
+ has160_pyobj = PyMapping_GetItemString(d, "has160"); Py_INCREF(has160_pyobj);
INSERT("GCMAC", gcmac_pytype);
INSERT("GMAC", gmac_pytype);
INSERT("GMACHash", gmhash_pytype);
- INSERT("gcmacs", gcmacs());
+ INSERT("gcmacs", make_algtab(gmactab, sizeof(gcmac *),
+ mac_namefn, mac_valfn));
INSERT("Poly1305Class", poly1305cls_pytype);
INSERT("poly1305", poly1305key_pytype);
INSERT("Poly1305Hash", poly1305hash_pytype);
INSERT("Shake256", shake256_pytype);
INSERT("GCPRP", gcprp_pytype);
INSERT("GPRP", gprp_pytype);
- INSERT("gcprps", gcprps());
+ INSERT("gcprps", make_algtab(gprptab, sizeof(gcprp *),
+ prp_namefn, prp_valfn));
setconstants(mod, consts);
}