X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/blobdiff_plain/df9f83669cecb76bb6ab25f42ce25d060f6cf98d..03ed9abbf0e1ccfc30a910f02c1d5e0cec4c7585:/catacomb-python.h diff --git a/catacomb-python.h b/catacomb-python.h index ff99a78..d71caa9 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -39,9 +39,13 @@ #include #include +#undef ULLONG_MAX +#undef ULONG_LONG_MAX + #include #include #include +#include #include @@ -55,6 +59,7 @@ #include #include #include +#include #include #include @@ -104,6 +109,9 @@ #include #include +#include +#include + /*----- Utility macros ----------------------------------------------------*/ #define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0) @@ -122,6 +130,10 @@ #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str) #define SYNERR(str) EXCERR(PyExc_SyntaxError, str) #define SYSERR(str) EXCERR(PyExc_SystemError, str) +#define INDEXERR(idx) do { \ + PyErr_SetObject(PyExc_KeyError, idx); \ + goto end; \ +} while (0) #define OSERR(name) do { \ PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \ goto end; \ @@ -152,6 +164,9 @@ PyModule_AddObject(mod, name, _o); \ } while (0) +#define INSEXC(name, var, base, meth) \ + INSERT(name, var = mkexc(mod, base, name, meth)) + #define METH(func, doc) \ { #func, METHNAME(func), METH_VARARGS, doc }, #define KWMETH(func, doc) \ @@ -166,11 +181,11 @@ #define MEMBER(name, ty, f, doc) \ { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc }, -#define MODULES(DO) \ - DO(bytestring) \ - DO(rand) DO(algorithms) DO(pubkey) DO(pgen) \ - DO(mp) DO(field) DO(ec) DO(group) \ - DO(passphrase) +#define MODULES(_) \ + _(bytestring) _(buffer) \ + _(rand) _(algorithms) _(pubkey) _(pgen) \ + _(mp) _(field) _(ec) _(group) \ + _(passphrase) _(share) _(key) #define DOMODINIT(m) m##_pyinit(); #define DOMODINSERT(m) m##_pyinsert(mod); #define INIT_MODULES do { MODULES(DOMODINIT) } while (0) @@ -236,7 +251,6 @@ extern mp *getfe(field *, PyObject *); typedef struct fe_pyobj { PyObject_HEAD field *f; - PyObject *fobj; /* to keep it alive */ mp *x; } fe_pyobj; @@ -271,7 +285,7 @@ extern PyObject *ecpt_pywrapout(void *, ec *); extern int toecpt(ec_curve *, ec *, PyObject *); extern int getecpt(ec_curve *, ec *, PyObject *); extern void getecptout(ec *, PyObject *); -extern int convec(PyObject *, void *); +extern int convecpt(PyObject *, void *); typedef struct eccurve_pyobj { PyHeapTypeObject ty; @@ -460,8 +474,6 @@ extern PyTypeObject *gmac_pytype; extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned); extern int convgmac(PyObject *, void *); -/*----- Public key crypto -------------------------------------------------*/ - /*----- Key generation ----------------------------------------------------*/ typedef struct pfilt_pyobj { @@ -500,14 +512,17 @@ extern PyObject *mexp_common(PyObject *, PyObject *, size_t, void (*drop)(void *)); extern int convulong(PyObject *, void *); -extern int convu32(PyObject *, void *); +#define DECL_CONVU_(n) extern int convu##n(PyObject *, void *); +DOUINTSZ(DECL_CONVU_) extern int convmpw(PyObject *, void *); extern int convuint(PyObject *, void *); extern int convszt(PyObject *, void *); extern int convbool(PyObject *, void *); extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *); extern PyObject *getbool(int); -extern PyObject *getu32(uint32); +#define DECL_GETU_(n) extern PyObject *getu##n(uint##n); +DOUINTSZ(DECL_GETU_) +extern PyObject * mkexc(PyObject *, PyObject *, const char *, PyMethodDef *); extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *); extern PyTypeObject *inittype(PyTypeObject *); extern void addmethods(const PyMethodDef *);