PyTypeObject *keyszany_pytype, *keyszrange_pytype, *keyszset_pytype;
PyObject *sha_pyobj, *has160_pyobj;
+#ifndef KSZ_OPMASK
+# define KSZ_OPMASK 0x1f
+#endif
+
+#ifndef KSZ_16BIT
+# define KSZ_16BIT 0x20
+#endif
+
PyObject *keysz_pywrap(const octet *k)
{
- switch (k[0]) {
+ unsigned op = *k++;
+#define ARG(i) (op&KSZ_16BIT ? LOAD16(k + 2*(i)) : k[i])
+ switch (op&KSZ_OPMASK) {
case KSZ_ANY: {
keysz_pyobj *o = PyObject_New(keysz_pyobj, keyszany_pytype);
- o->dfl = k[1];
+ o->dfl = ARG(0);
return ((PyObject *)o);
} break;
case KSZ_RANGE: {
keyszrange_pyobj *o =
PyObject_New(keyszrange_pyobj, keyszrange_pytype);
- o->dfl = k[1];
- o->min = k[2];
- o->max = k[3];
- o->mod = k[4];
+ o->dfl = ARG(0);
+ o->min = ARG(1);
+ o->max = ARG(2);
+ o->mod = ARG(3);
if (!o->mod) o->mod = 1;
return ((PyObject *)o);
} break;
keyszset_pyobj *o =
PyObject_New(keyszset_pyobj, keyszset_pytype);
int i, n;
- o->dfl = k[1];
- for (i = 0; k[i + 1]; i++) ;
+ o->dfl = ARG(0);
+ for (i = 0; ARG(i); i++) ;
n = i; o->set = PyTuple_New(n);
for (i = 0; i < n; i++)
- PyTuple_SET_ITEM(o->set, i, PyInt_FromLong(k[i + 1]));
+ PyTuple_SET_ITEM(o->set, i, PyInt_FromLong(ARG(i)));
return ((PyObject *)o);
} break;
default:
abort();
}
+#undef ARG
}
static PyObject *keyszany_pynew(PyTypeObject *ty,
## For the benefit of the default keyreporter, we need the program na,e.
_base._ego(_argv[0])
+## How to fix a name back into the right identifier. Alas, the rules are not
+## consistent.
+def _fixname(name):
+
+ ## Hyphens consistently become underscores.
+ name = name.replace('-', '_')
+
+ ## But slashes might become underscores or just vanish.
+ if name.startswith('salsa20'): name = name.translate(None, '/')
+ else: name = name.replace('/', '_')
+
+ ## Done.
+ return name
+
## Initialize the module. Drag in the static methods of the various
## classes; create names for the various known crypto algorithms.
def _init():
setattr(c, j[plen:], classmethod(b[j]))
for i in [gcciphers, gchashes, gcmacs, gcprps]:
for c in i.itervalues():
- d[c.name.replace('-', '_').translate(None, '/')] = c
+ d[_fixname(c.name)] = c
for c in gccrands.itervalues():
- d[c.name.replace('-', '_').translate(None, '/') + 'rand'] = c
+ d[_fixname(c.name + 'rand')] = c
_init()
## A handy function for our work: add the methods of a named class to an
+catacomb-python (1.1.2) experimental; urgency=low
+
+ * Further 64-bit compatibility improvements.
+ * Fixed docstrings for a number of native methods.
+ * Fix range checking for `GRand' methods.
+ * Fix crash when deleting natively implemented object attributes.
+ * Fix bug which assigned the wrong hash to bytestrings.
+ * Fix `__int__' methods to return `long' objects when necessary.
+ Without this, there are unnecessary failures and bizarrely timed
+ exceptions.
+ * A couple of patches to provide forward compatibility with upstream
+ library changes.
+
+ -- Mark Wooding <mdw@distorted.org.uk> Sun, 14 May 2017 04:25:35 +0100
+
catacomb-python (1.1.1) experimental; urgency=low
* ByteString operators: fix crashes on 64-bit platforms resulting from
unsigned long *p = pp;
PyObject *t;
+ if (!o) VALERR("can't delete");
if (PyInt_Check(o)) {
i = PyInt_AS_LONG(o);
if (i < 0) VALERR("must be nonnegative");
int convbool(PyObject *o, void *pp)
{
+ if (!o) VALERR("can't delete");
*(int *)pp = PyObject_IsTrue(o);
return (1);
+end:
+ return (0);
}
/*----- Type messing ------------------------------------------------------*/