]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: keys: Export algorithm and key length
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Oct 2022 11:18:58 +0000 (11:18 +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/key.c

index 0807fd5cf4a6417c5573147262e0ffa158bc7c76..90fa9ee7cfcc5736d0fc048642751c73fd1087a7 100644 (file)
@@ -138,6 +138,24 @@ static PyObject* Key_get_email(KeyObject* self) {
        return PyUnicode_FromString(email);
 }
 
+static PyObject* Key_get_algo(KeyObject* self) {
+       const char* algo = pakfire_key_get_pubkey_algo(self->key);
+
+       // Raise an error on no input
+       if (!algo) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       return PyUnicode_FromString(algo);
+}
+
+static PyObject* Key_get_length(KeyObject* self) {
+       const size_t length = pakfire_key_get_pubkey_length(self->key);
+
+       return PyLong_FromLong(length);
+}
+
 static PyObject* Key_export(KeyObject* self, PyObject* args) {
        PyObject* file = NULL;
        int secret = 0;
@@ -246,6 +264,13 @@ static struct PyMethodDef Key_methods[] = {
 };
 
 static struct PyGetSetDef Key_getsetters[] = {
+       {
+               "algo",
+               (getter)Key_get_algo,
+               NULL,
+               NULL,
+               NULL,
+       },
        {
                "created_at",
                (getter)Key_get_created_at,
@@ -274,6 +299,13 @@ static struct PyGetSetDef Key_getsetters[] = {
                NULL,
                NULL,
        },
+       {
+               "length",
+               (getter)Key_get_length,
+               NULL,
+               NULL,
+               NULL,
+       },
        {
                "name",
                (getter)Key_get_name,