#include <catacomb/dsarand.h>
#include <catacomb/sslprf.h>
#include <catacomb/tlsprf.h>
+#include <catacomb/blkc.h>
#include <catacomb/gcipher.h>
#include <catacomb/ghash.h>
#define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
#define SYNERR(str) EXCERR(PyExc_SyntaxError, str)
#define SYSERR(str) EXCERR(PyExc_SystemError, str)
+#define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
#define INDEXERR(idx) do { \
PyErr_SetObject(PyExc_KeyError, idx); \
goto end; \
#define FREEOBJ(obj) \
(((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
+#define GEN(func, base) \
+ static PyObject *func(void) \
+ { \
+ PyObject *d = PyDict_New(); \
+ PyObject *o; \
+ int i; \
+ \
+ for (i = 0; g##base##tab[i]; i++) { \
+ o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \
+ PyDict_SetItemString(d, \
+ (/*unconst*/ char *)g##base##tab[i]->name, \
+ o); \
+ Py_DECREF(o); \
+ } \
+ return (d); \
+ }
+
+struct nameval { const char *name; unsigned long value; };
+extern void setconstants(PyObject *, const struct nameval *);
+
+extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
+ PyObject *(*id)(PyObject *),
+ int (*fill)(void *, PyObject *,
+ PyObject *, PyObject *),
+ PyObject *(*exp)(PyObject *, void *, int),
+ void (*drop)(void *));
+
+extern int convulong(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);
+#define DECL_GETU_(n) extern PyObject *getu##n(uint##n);
+DOUINTSZ(DECL_GETU_)
+extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
+
+extern PyObject * mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
+extern PyTypeObject *inittype(PyTypeObject *);
+extern void addmethods(const PyMethodDef *);
+extern PyMethodDef *donemethods(void);
+
+/*----- Mapping methods ---------------------------------------------------*/
+
+#define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
+#define GMAP_KWMETH(func, doc) \
+ { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
+#define GMAP_METHDECL(func, doc) \
+ extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
+#define GMAP_KWMETHDECL(func, doc) \
+ extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
+
+#define GMAP_DOROMETHODS(METH, KWMETH) \
+ METH (has_key, "D.has_key(KEY) -> BOOL") \
+ METH (keys, "D.keys() -> LIST") \
+ METH (values, "D.values() -> LIST") \
+ METH (items, "D.items() -> LIST") \
+ METH (iterkeys, "D.iterkeys() -> ITER") \
+ METH (itervalues, "D.itervalues() -> ITER") \
+ METH (iteritems, "D.iteritems() -> ITER") \
+ KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \
+
+#define GMAP_DOMETHODS(METH, KWMETH) \
+ GMAP_DOROMETHODS(METH, KWMETH) \
+ METH (clear, "D.clear()") \
+ KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \
+ KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \
+ METH (popitem, "D.popitem() -> (KEY, VALUE)") \
+ METH (update, "D.update(MAP)")
+
+GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
+#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
+#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
+extern int gmap_pysize(PyObject *);
+extern PySequenceMethods gmap_pysequence;
+extern PyMethodDef gmap_pymethods[];
+
/*----- Bytestrings -------------------------------------------------------*/
PyTypeObject *bytestring_pyobj;
#define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
#define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
-extern mp *mp_frompylong(PyLongObject *);
-extern PyLongObject *mp_topylong(mp *);
+extern mp *mp_frompylong(PyObject *);
+extern PyObject *mp_topylong(mp *);
extern mp *tomp(PyObject *);
extern mp *getmp(PyObject *);
extern int convmp(PyObject *, void *);
extern void droppgev(pgev *);
extern void pgenerr(void);
-/*----- Core utility functions --------------------------------------------*/
-
-extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
- PyObject *(*id)(PyObject *),
- int (*fill)(void *, PyObject *,
- PyObject *, PyObject *),
- PyObject *(*exp)(PyObject *, void *, int),
- void (*drop)(void *));
-
-extern int convulong(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);
-#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 *);
-
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus