return 0;
}
+static PyObject* _File_digest(FileObject* self, enum pakfire_digests type) {
+ size_t length = 0;
+
+ // Fetch the digest
+ const unsigned char* digest = pakfire_file_get_digest(self->file, type, &length);
+ if (!digest)
+ Py_RETURN_NONE;
+
+ return PyBytes_FromStringAndSize((const char*)digest, length);
+}
+
+static PyObject* File_digest(FileObject* self, PyObject* args) {
+ int type = 0;
+
+ if (!PyArg_ParseTuple(args, "i", &type))
+ return NULL;
+
+ return _File_digest(self, type);
+}
+
+static PyObject* _File_hexdigest(FileObject* self, enum pakfire_digests type) {
+ const char* hexdigest = pakfire_file_get_hexdigest(self->file, type);
+ if (!hexdigest)
+ Py_RETURN_NONE;
+
+ return PyUnicode_FromString(hexdigest);
+}
+
+static PyObject* File_hexdigest(FileObject* self, PyObject* args) {
+ int type = 0;
+
+ if (!PyArg_ParseTuple(args, "i", &type))
+ return NULL;
+
+ return _File_hexdigest(self, type);
+}
+
+static struct PyMethodDef File_methods[] = {
+ {
+ "digest",
+ (PyCFunction)File_digest,
+ METH_VARARGS,
+ NULL,
+ },
+ {
+ "hexdigest",
+ (PyCFunction)File_hexdigest,
+ METH_VARARGS,
+ NULL,
+ },
+ { NULL },
+};
+
static struct PyGetSetDef File_getsetters[] = {
{
"ctime",
tp_dealloc: (destructor)File_dealloc,
tp_init: (initproc)File_init,
tp_doc: "File object",
+ tp_methods: File_methods,
tp_getset: File_getsetters,
tp_repr: (reprfunc)File_repr,
tp_str: (reprfunc)File_get_path,