/* -*-c-*-
- *
- * $Id$
*
* Key files and data
*
* (c) 2005 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of the Python interface to Catacomb.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* Catacomb/Python is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with Catacomb/Python; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
rc = 1;
goto end;
tyerr:
- TYERR("expected flag string or flag/mask pair");
+ TYERR("expected flag string or integer bitfield");
end:
return (rc);
}
static PyObject *kdmeth_matchp(PyObject *me, PyObject *arg)
{
key_filter f;
-
+
if (!PyArg_ParseTuple(arg, "O&:matchp", convfilter, &f))
return (0);
return (getbool(KEY_MATCH(KEYDATA_KD(me), &f)));
RETURN_ME;
}
+static PyObject *kdmeth_copy(PyObject *me, PyObject *arg, PyObject *kw)
+{
+ key_filter f = { 0, 0 };
+ static char *kwlist[] = { "filter", 0 };
+ key_data *kd;
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:copy", kwlist,
+ convfilter, &f))
+ return (0);
+ if ((kd = key_copydata(KEYDATA_KD(me), &f)) == 0)
+ RETURN_NONE;
+ else
+ return (keydata_pywrap(kd));
+}
+
static PyObject *kdmeth_write(PyObject *me, PyObject *arg, PyObject *kw)
{
key_filter f = { 0, 0 };
int err;
PyObject *rc = 0;
key_data *kd;
-
+
if (!PyArg_ParseTuple(arg, "s:plock", &tag))
goto end;
if ((err = key_plock(&kd, KEYDATA_KD(me), tag)) != 0)
int n;
PyObject *rc = 0;
key_data *kd;
-
+
if (!PyArg_ParseTuple(arg, "s#:lock", &p, &n))
goto end;
key_lock(&kd, KEYDATA_KD(me), p, n);
goto end;
if ((kd = key_decode(p, n)) == 0)
KEYERR(KERR_MALFORMED);
- rc = keydata_pywrap(kd);
+ rc = keydata_pywrap(kd);
end:
return (rc);
}
METH (split, "KD.split()")
KWMETH(write, "KD.write(filter = <any>) -> STRING")
KWMETH(encode, "KD.encode(filter = <any>) -> BYTES")
+ KWMETH(copy, "KD.encode(filter = <any>) -> KD")
METH (plock, "KD.plock(TAG) -> ENCRYPTED-KD")
METH (lock, "KD.lock(KEY) -> ENCRYPTED-KD")
#undef METHNAME
int err;
PyObject *rc = 0;
key_data *kd;
-
+
if (!PyArg_ParseTuple(arg, "s:punlock", &tag))
goto end;
if ((err = key_punlock(&kd, KEYDATA_KD(me), tag)) != 0)
int err;
PyObject *rc = 0;
key_data *kd;
-
+
if (!PyArg_ParseTuple(arg, "s#:unlock", &p, &n))
goto end;
if ((err = key_unlock(&kd, KEYDATA_KD(me), p, n)) != 0)
if ((tag = PyString_AsString(key)) == 0)
goto end;
+ key_split(&KEYDATA_KD(me));
if (value) {
if (!KEYDATA_PYCHECK(value))
TYERR("expected KeyData value");
static PyObject *kmeth_delete(PyObject *me, PyObject *arg)
{
int err;
-
+
if (!PyArg_ParseTuple(arg, ":delete")) goto end;
if ((err = key_delete(KEY_KF(me), KEY_K(me))) != 0) KEYERR(err);
RETURN_ME;
static PyObject *kmeth_expire(PyObject *me, PyObject *arg)
{
int err;
-
+
if (!PyArg_ParseTuple(arg, ":expire")) goto end;
if ((err = key_expire(KEY_KF(me), KEY_K(me))) != 0) KEYERR(err);
RETURN_ME;
{
long t;
int err;
-
+
if (!PyArg_ParseTuple(arg, "l:used", &t)) goto end;
if ((err = key_used(KEY_KF(me), KEY_K(me), t)) != 0) KEYERR(err);
RETURN_ME;
key *k = KEY_K(me);
unsigned long et;
- if ((et = PyLong_AsUnsignedLong(x)) == (unsigned long)-1 && PyErr_Occurred())
+ if (!convulong(x, &et))
goto end;
if (!(KEY_KF(me)->f & KF_WRITE))
KEYERR(KERR_READONLY);
key *k = KEY_K(me);
unsigned long dt;
- if ((dt = PyLong_AsUnsignedLong(x)) == (unsigned long)-1 && PyErr_Occurred())
+ if (!convulong(x, &dt))
goto end;
if (dt == KEXP_FOREVER && k->exp != KEXP_FOREVER)
VALERR("key will eventually expire");
if ((k = key_next(KEYITER_I(me))) == 0)
return (0);
- return (key_pywrap(KEYITER_KFOBJ(me), k));
+ return (getulong(k->id));
}
static void keyiter_pydealloc(PyObject *me)
}
end:
return (rc);
-}
+}
static PyObject *kfmeth_newkey(PyObject *me, PyObject *arg, PyObject *kw)
{
key *k;
int err;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&sl:new", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&s|l:newkey", kwlist,
convu32, &id, &type, &exptime))
goto end;
- if ((err = key_new(KEYFILE_KF(me), id, type, exptime, &k)) == 0)
+ if ((err = key_new(KEYFILE_KF(me), id, type, exptime, &k)) != 0)
KEYERR(err);
return (key_pywrap(me, k));
end: