From 0c1ad364d65c4144ff71c376e0b49fbc322b686d Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 29 Nov 2021 14:01:39 +0200 Subject: Add Python bindings for rpmfilesFSignature() and rpmfilesVSignature() Only, use more descriptive names than the C-side counterparts. Python has nice facilities for dealing with binary data so return it as such rather than converting to hex. --- python/rpmfiles-py.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'python') diff --git a/python/rpmfiles-py.c b/python/rpmfiles-py.c index 84f3dc72f..2d8c2111a 100644 --- a/python/rpmfiles-py.c +++ b/python/rpmfiles-py.c @@ -152,6 +152,29 @@ static PyObject *rpmfile_digest(rpmfileObject *s) Py_RETURN_NONE; } +static PyObject *bytebuf(const unsigned char *buf, size_t len) +{ + if (buf) { + PyObject *o = PyBytes_FromStringAndSize((const char *)buf, len); + return o; + } + Py_RETURN_NONE; +} + +static PyObject *rpmfile_imasig(rpmfileObject *s) +{ + size_t len = 0; + const unsigned char *sig = rpmfilesFSignature(s->files, s->ix, &len); + return bytebuf(sig, len); +} + +static PyObject *rpmfile_veritysig(rpmfileObject *s) +{ + size_t len = 0; + const unsigned char *sig = rpmfilesVSignature(s->files, s->ix, &len, NULL); + return bytebuf(sig, len); +} + static PyObject *rpmfile_class(rpmfileObject *s) { return utf8FromString(rpmfilesFClass(s->files, s->ix)); @@ -278,6 +301,10 @@ static PyGetSetDef rpmfile_getseters[] = { "language the file provides (typically for doc files)" }, { "caps", (getter) rpmfile_caps, NULL, "file capabilities" }, + { "imasig", (getter) rpmfile_imasig, NULL, + "IMA signature" }, + { "veritysig", (getter) rpmfile_veritysig, NULL, + "Verity signature" }, { NULL, NULL, NULL, NULL } }; -- cgit v1.2.1