static PyObject *gfsharesplit_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
- char *p;
- Py_ssize_t n;
+ struct bin in;
unsigned t;
grand *r = &rand_global;
gfshare_pyobj *s;
static const char *const kwlist[] = { "threshold", "secret", "rng", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&s#|O&:new", KWLIST,
- convuint, &t, &p, &n, convgrand, &r))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|O&:new", KWLIST,
+ convuint, &t, convbin, &in,
+ convgrand, &r))
goto end;
if (!t || t > 255) VALERR("threshold must be nonzero and < 256");
s = (gfshare_pyobj *)ty->tp_alloc(ty, 0);
- gfshare_create(&s->s, t, n);
- gfshare_mkshares(&s->s, r, p);
+ gfshare_create(&s->s, t, in.sz);
+ gfshare_mkshares(&s->s, r, in.p);
return ((PyObject *)s);
end:
return (0);
if (!PyArg_ParseTuple(arg, "O&:get", convuint, &i)) goto end;
if (i >= 255) VALERR("index must be < 255");
rc = bytestring_pywrap(0, GFSHARE_S(me)->sz);
- gfshare_get(GFSHARE_S(me), i, PyString_AS_STRING(rc));
+ gfshare_get(GFSHARE_S(me), i, BIN_PTR(rc));
end:
return (rc);
}
static PyObject *gfsmeth_add(PyObject *me, PyObject *arg)
{
unsigned i;
- char *p;
- Py_ssize_t n;
- if (!PyArg_ParseTuple(arg, "O&s#:add", convuint, &i, &p, &n)) goto end;
+ struct bin s;
+ if (!PyArg_ParseTuple(arg, "O&O&:add", convuint, &i, convbin, &s))
+ goto end;
if (i > 254) VALERR("index must be < 255");
- if (n != GFSHARE_S(me)->sz) VALERR("bad share size");
+ if (s.sz != GFSHARE_S(me)->sz) VALERR("bad share size");
if (gfshare_addedp(GFSHARE_S(me), i)) VALERR("this share already added");
if (GFSHARE_S(me)->i >= GFSHARE_S(me)->t) VALERR("enough shares already");
- gfshare_add(GFSHARE_S(me), i, p);
+ gfshare_add(GFSHARE_S(me), i, s.p);
return (PyInt_FromLong(GFSHARE_S(me)->t - GFSHARE_S(me)->i));
end:
return (0);
PyObject *rc = 0;
if (GFSHARE_S(me)->i < GFSHARE_S(me)->t) VALERR("not enough shares yet");
rc = bytestring_pywrap(0, GFSHARE_S(me)->sz);
- gfshare_combine(GFSHARE_S(me), PyString_AS_STRING(rc));
+ gfshare_combine(GFSHARE_S(me), BIN_PTR(rc));
end:
return (rc);
}