X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/2a3f4da1c95d71e6045ddf1617754bacddfd46c3..6286102d3187aa7bb36859fe626c85f3220722fd:/passphrase.c diff --git a/passphrase.c b/passphrase.c index 1796629..424bcc9 100644 --- a/passphrase.c +++ b/passphrase.c @@ -92,7 +92,7 @@ static PyObject *pixmeth_read(PyObject *me, PyObject *arg, PyObject *kw) else if (r > 0) RETURN_NONE; else - rc = PyString_FromString(buf); + rc = BIN_FROMSTR(buf); end: return (rc); } @@ -102,7 +102,7 @@ static PyObject *pixmeth_set(PyObject *me, PyObject *arg) char *tag; char *phrase; - if (!PyArg_ParseTuple(arg, "ss:set", &tag, &phrase)) + if (!PyArg_ParseTuple(arg, "s"Y":set", &tag, &phrase)) return (0); pixie_set(PIXIE_FD(me), tag, phrase); RETURN_ME; @@ -118,7 +118,7 @@ static PyObject *pixmeth_cancel(PyObject *me, PyObject *arg) RETURN_ME; } -static PyMethodDef pixie_pymethods[] = { +static const PyMethodDef pixie_pymethods[] = { #define METHNAME(name) pixmeth_##name KWMETH(read, "P.read(TAG, [mode = PMODE_READ]) -> STRING") METH (set, "P.set(TAG, PHRASE)") @@ -127,8 +127,8 @@ static PyMethodDef pixie_pymethods[] = { { 0 } }; -static PyTypeObject pixie_pytype_skel = { - PyObject_HEAD_INIT(0) 0, /* Header */ +static const PyTypeObject pixie_pytype_skel = { + PyVarObject_HEAD_INIT(0, 0) /* Header */ "Pixie", /* @tp_name@ */ sizeof(pixie_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -152,7 +152,7 @@ static PyTypeObject pixie_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Pixie([socket = ?]): passphrase pixie connection.", + "Pixie([socket = ?]): passphrase pixie connection.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -160,7 +160,7 @@ static PyTypeObject pixie_pytype_skel = { 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ - pixie_pymethods, /* @tp_methods@ */ + PYMETHODS(pixie), /* @tp_methods@ */ 0, /* @tp_members@ */ 0, /* @tp_getset@ */ 0, /* @tp_base@ */ @@ -177,6 +177,11 @@ static PyTypeObject pixie_pytype_skel = { /*----- Main code ---------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(PMODE_READ), CONST(PMODE_VERIFY), + { 0 } +}; + static PyObject *meth_ppread(PyObject *me, PyObject *arg, PyObject *kw) { char *tag; @@ -190,7 +195,7 @@ static PyObject *meth_ppread(PyObject *me, PyObject *arg, PyObject *kw) goto end; if (passphrase_read(tag, f, buf, sizeof(buf))) SYSERR("passphrase read failed"); - rc = PyString_FromString(buf); + rc = BIN_FROMSTR(buf); end: return (rc); } @@ -215,16 +220,16 @@ static PyObject *meth_getpass(PyObject *me, PyObject *arg) goto end; if (pixie_getpass(prompt, buf, sizeof(buf))) OSERR(0); - rc = PyString_FromString(buf); + rc = BIN_FROMSTR(buf); end: return (rc); } -static PyMethodDef methods[] = { +static const PyMethodDef methods[] = { #define METHNAME(name) meth_##name - KWMETH(ppread, "ppread(TAG, [mode = PMODE_READ]) -> STRING") - METH (ppcancel, "ppcancel(TAG)") - METH (getpass, "getpass(PROMPT) -> STRING") + KWMETH(ppread, "ppread(TAG, [mode = PMODE_READ]) -> STRING") + METH (ppcancel, "ppcancel(TAG)") + METH (getpass, "getpass(PROMPT) -> STRING") #undef METHNAME { 0 } }; @@ -238,6 +243,7 @@ void passphrase_pyinit(void) void passphrase_pyinsert(PyObject *mod) { INSERT("Pixie", pixie_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/