]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Return digest for packages only as binary
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Oct 2022 10:55:23 +0000 (10:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Oct 2022 11:19:34 +0000 (11:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/package.c

index a9fbdbe8afa3d20ac7b0ded5140919f408fdd478..6768db4493efc244616ecd72e800e25d42639aee 100644 (file)
@@ -194,41 +194,17 @@ static void Package_set_uuid(PackageObject* self, PyObject* value) {
        pakfire_package_set_uuid(self->package, uuid);
 }
 
-static PyObject* Package_get_hexdigest(PackageObject* self, enum pakfire_digest_types type) {
-       enum pakfire_digest_types digest = 0;
-
-       const char* hexdigest = pakfire_package_get_hexdigest(self->package, &digest);
-       if (!hexdigest)
-               Py_RETURN_NONE;
-
-       // Is this the requested type?
-       if (digest != type)
+static PyObject* Package_get_digest(PackageObject* self) {
+       enum pakfire_digest_types type = PAKFIRE_DIGEST_UNDEFINED;
+       const unsigned char* digest = NULL;
+       size_t length = 0;
+
+       // Fetch the digest
+       digest = pakfire_package_get_digest(self->package, &type, &length);
+       if (!digest)
                Py_RETURN_NONE;
 
-       return PyUnicode_FromString(hexdigest);
-}
-
-static PyObject* Package_get_hexdigest_sha2_256(PackageObject* self) {
-       return Package_get_hexdigest(self, PAKFIRE_DIGEST_SHA2_256);
-}
-
-static PyObject* Package_get_hexdigest_sha2_512(PackageObject* self) {
-       return Package_get_hexdigest(self, PAKFIRE_DIGEST_SHA2_512);
-}
-
-static int Package_set_hexdigest(PackageObject* self,
-               const enum pakfire_digest_types type, PyObject* value) {
-       const char* hexdigest = PyUnicode_FromValue(value);
-
-       return pakfire_package_set_hexdigest(self->package, type, hexdigest);
-}
-
-static int Package_set_hexdigest_sha2_256(PackageObject* self, PyObject* value) {
-       return Package_set_hexdigest(self, PAKFIRE_DIGEST_SHA2_256, value);
-}
-
-static int Package_set_hexdigest_sha2_512(PackageObject* self, PyObject* value) {
-       return Package_set_hexdigest(self, PAKFIRE_DIGEST_SHA2_512, value);
+       return Py_BuildValue("(sy#)", pakfire_digest_name(type), digest, length);
 }
 
 static PyObject* Package_get_summary(PackageObject* self) {
@@ -741,7 +717,7 @@ static struct PyMethodDef Package_methods[] = {
                "dump",
                (PyCFunction)Package_dump,
                METH_VARARGS|METH_KEYWORDS,
-               NULL
+               NULL,
        },
        { NULL },
 };
@@ -776,18 +752,11 @@ static struct PyGetSetDef Package_getsetters[] = {
                NULL
        },
        {
-               "hexdigest_sha2_256",
-               (getter)Package_get_hexdigest_sha2_256,
-               (setter)Package_set_hexdigest_sha2_256,
+               "digest",
+               (getter)Package_get_digest,
+               NULL,
                NULL,
-               NULL
-       },
-       {
-               "hexdigest_sha2_512",
-               (getter)Package_get_hexdigest_sha2_512,
-               (setter)Package_set_hexdigest_sha2_512,
                NULL,
-               NULL
        },
        {
                "summary",