algorithms.c: Add bindings for STROBE.
[catacomb-python] / passphrase.c
index 25d448b..424bcc9 100644 (file)
@@ -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;
@@ -128,7 +128,7 @@ static const PyMethodDef pixie_pymethods[] = {
 };
 
 static const PyTypeObject pixie_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "Pixie",                             /* @tp_name@ */
   sizeof(pixie_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -177,6 +177,11 @@ static const 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,7 +220,7 @@ 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);
 }
@@ -238,6 +243,7 @@ void passphrase_pyinit(void)
 void passphrase_pyinsert(PyObject *mod)
 {
   INSERT("Pixie", pixie_pytype);
+  setconstants(mod, consts);
 }
 
 /*----- That's all, folks -------------------------------------------------*/