From: Michael Tremer Date: Sat, 1 Oct 2022 13:19:54 +0000 (+0000) Subject: _pakfire: Fetch digest type by string X-Git-Tag: 0.9.28~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c1e4b44a861fd4bccd72b6e957f05428be27ebc;p=pakfire.git _pakfire: Fetch digest type by string Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/file.c b/src/_pakfire/file.c index fff20d8ee..e8384b279 100644 --- a/src/_pakfire/file.c +++ b/src/_pakfire/file.c @@ -228,7 +228,21 @@ static int File_set_mtime(FileObject* self, PyObject* value) { return 0; } -static PyObject* _File_digest(FileObject* self, enum pakfire_digest_types type) { +static PyObject* File_digest(FileObject* self, PyObject* args) { + const char* name = NULL; + + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + + // Fetch the type + const enum pakfire_digest_types type = pakfire_digest_get_by_name(name); + + // Raise ValueError if we could not find the type + if (!type) { + PyErr_Format(PyExc_ValueError, "Unknown digest type: %s", name); + return NULL; + } + size_t length = 0; // Fetch the digest @@ -239,15 +253,6 @@ static PyObject* _File_digest(FileObject* self, enum pakfire_digest_types type) 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_digest_types type) { char* hexdigest = pakfire_file_get_hexdigest(self->file, type); if (!hexdigest)