~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*.py: Add explicit conversions between binary and text strings.
[catacomb-python]
/
group.c
diff --git
a/group.c
b/group.c
index
51e0fd9
..
b51cb6a
100644
(file)
--- a/
group.c
+++ b/
group.c
@@
-196,8
+196,7
@@
static PyObject *dimeth_gendsa(PyObject *me, PyObject *arg, PyObject *kw)
unsigned ql, pl;
unsigned steps = 0;
dsa_seed ds;
unsigned ql, pl;
unsigned steps = 0;
dsa_seed ds;
- char *k;
- Py_ssize_t ksz;
+ struct bin k;
struct excinfo exc = EXCINFO_INIT;
pypgev evt = { { 0 } };
static const char *const kwlist[] =
struct excinfo exc = EXCINFO_INIT;
pypgev evt = { { 0 } };
static const char *const kwlist[] =
@@
-205,12
+204,12
@@
static PyObject *dimeth_gendsa(PyObject *me, PyObject *arg, PyObject *kw)
PyObject *rc = 0;
evt.exc = &exc;
PyObject *rc = 0;
evt.exc = &exc;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&
s#
|O&O&:gendsa", KWLIST,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&
O&
|O&O&:gendsa", KWLIST,
convuint, &pl, convuint, &ql,
convuint, &pl, convuint, &ql,
-
&k, &ksz, convpgev, &evt
,
- convuint, &steps))
+
convbin, &k
,
+ conv
pgev, &evt, conv
uint, &steps))
goto end;
goto end;
- if (dsa_gen(&dp, ql, pl, steps, k
, k
sz, &ds, evt.ev.proc, evt.ev.ctx))
+ if (dsa_gen(&dp, ql, pl, steps, k
.p, k.
sz, &ds, evt.ev.proc, evt.ev.ctx))
PGENERR(&exc);
rc = Py_BuildValue("(NNl)", fginfo_pywrap(&dp, dhinfo_pytype),
bytestring_pywrap(ds.p, ds.sz), (long)ds.count);
PGENERR(&exc);
rc = Py_BuildValue("(NNl)", fginfo_pywrap(&dp, dhinfo_pytype),
bytestring_pywrap(ds.p, ds.sz), (long)ds.count);
@@
-494,6
+493,7
@@
static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
ec p = EC_INIT;
mp *y = 0;
ge *xx = 0;
ec p = EC_INIT;
mp *y = 0;
ge *xx = 0;
+ size_t n;
mptext_stringctx sc;
g = GROUP_G(ty);
mptext_stringctx sc;
g = GROUP_G(ty);
@@
-508,9
+508,8
@@
static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
if (G_FROMINT(g, xx, y))
TYERR("can't convert from integer");
MP_DROP(y);
if (G_FROMINT(g, xx, y))
TYERR("can't convert from integer");
MP_DROP(y);
- } else if (PyString_Check(x)) {
- sc.buf = PyString_AS_STRING(x);
- sc.lim = sc.buf + PyString_GET_SIZE(x);
+ } else if (TEXT_CHECK(x)) {
+ TEXT_PTRLEN(x, sc.buf, n); sc.lim = sc.buf + n;
if (G_READ(g, xx, &mptext_stringops, &sc) || sc.buf < sc.lim)
VALERR("malformed group element string");
} else
if (G_READ(g, xx, &mptext_stringops, &sc) || sc.buf < sc.lim)
VALERR("malformed group element string");
} else
@@
-662,7
+661,7
@@
static PyObject *ge_pystr(PyObject *me)
PyObject *rc;
group_writedstr(GE_G(me), GE_X(me), &d);
PyObject *rc;
group_writedstr(GE_G(me), GE_X(me), &d);
- rc =
PyString_FromStringAndSize
(d.buf, d.len);
+ rc =
TEXT_FROMSTRLEN
(d.buf, d.len);
DDESTROY(&d);
return (rc);
}
DDESTROY(&d);
return (rc);
}
@@
-747,10
+746,10
@@
static PyObject *gemeth_tobuf(PyObject *me)
n = GE_G(me)->noctets + 4;
rc = bytestring_pywrap(0, n);
n = GE_G(me)->noctets + 4;
rc = bytestring_pywrap(0, n);
- buf_init(&b,
PyString_AS_STRING
(rc), n);
+ buf_init(&b,
BIN_PTR
(rc), n);
G_TOBUF(GE_G(me), &b, GE_X(me));
assert(BOK(&b));
G_TOBUF(GE_G(me), &b, GE_X(me));
assert(BOK(&b));
-
_PyString_Resize(&
rc, BLEN(&b));
+
BIN_SETLEN(
rc, BLEN(&b));
return (rc);
}
return (rc);
}
@@
-762,10
+761,10
@@
static PyObject *gemeth_toraw(PyObject *me)
n = GE_G(me)->noctets;
rc = bytestring_pywrap(0, n);
n = GE_G(me)->noctets;
rc = bytestring_pywrap(0, n);
- buf_init(&b,
PyString_AS_STRING
(rc), n);
+ buf_init(&b,
BIN_PTR
(rc), n);
G_TORAW(GE_G(me), &b, GE_X(me));
assert(BOK(&b));
G_TORAW(GE_G(me), &b, GE_X(me));
assert(BOK(&b));
-
_PyString_Resize(&
rc, BLEN(&b));
+
BIN_SETLEN(
rc, BLEN(&b));
return (rc);
}
return (rc);
}
@@
-820,14
+819,13
@@
end:
static PyObject *gemeth_frombuf(PyObject *me, PyObject *arg)
{
buf b;
static PyObject *gemeth_frombuf(PyObject *me, PyObject *arg)
{
buf b;
- char *p;
- Py_ssize_t n;
+ struct bin in;
group *g;
ge *x = 0;
group *g;
ge *x = 0;
- if (!PyArg_ParseTuple(arg, "
s#:frombuf", &p, &
n)) return (0);
+ if (!PyArg_ParseTuple(arg, "
O&:frombuf", convbin, &i
n)) return (0);
g = GROUP_G(me);
g = GROUP_G(me);
- buf_init(&b,
p, n
);
+ buf_init(&b,
(/*unconst*/ void *)in.p, in.sz
);
x = G_CREATE(g);
if (G_FROMBUF(g, &b, x)) VALERR("invalid data");
return (Py_BuildValue("(NN)", ge_pywrap(me, x), bytestring_pywrapbuf(&b)));
x = G_CREATE(g);
if (G_FROMBUF(g, &b, x)) VALERR("invalid data");
return (Py_BuildValue("(NN)", ge_pywrap(me, x), bytestring_pywrapbuf(&b)));
@@
-839,14
+837,13
@@
end:
static PyObject *gemeth_fromraw(PyObject *me, PyObject *arg)
{
buf b;
static PyObject *gemeth_fromraw(PyObject *me, PyObject *arg)
{
buf b;
- char *p;
- Py_ssize_t n;
+ struct bin in;
group *g;
ge *x = 0;
group *g;
ge *x = 0;
- if (!PyArg_ParseTuple(arg, "
s#:fromraw", &p, &
n)) return (0);
+ if (!PyArg_ParseTuple(arg, "
O&:fromraw", convbin, &i
n)) return (0);
g = GROUP_G(me);
g = GROUP_G(me);
- buf_init(&b,
p, n
);
+ buf_init(&b,
(/*unconst*/ void *)in.p, in.sz
);
x = G_CREATE(g);
if (G_FROMRAW(g, &b, x)) VALERR("invalid data");
return (Py_BuildValue("(NN)", ge_pywrap(me, x), bytestring_pywrapbuf(&b)));
x = G_CREATE(g);
if (G_FROMRAW(g, &b, x)) VALERR("invalid data");
return (Py_BuildValue("(NN)", ge_pywrap(me, x), bytestring_pywrapbuf(&b)));
@@
-912,7
+909,7
@@
static PyObject *gget_g(PyObject *me, void *hunoz)
G_COPY(g, x, g->g); return (ge_pywrap(me, x));
}
G_COPY(g, x, g->g); return (ge_pywrap(me, x));
}
-static
long
ge_pyhash(PyObject *me)
+static
Py_hash_t
ge_pyhash(PyObject *me)
{
buf b;
size_t sz = GE_G(me)->noctets + 4;
{
buf b;
size_t sz = GE_G(me)->noctets + 4;