]> git.ipfire.org Git - pakfire.git/commitdiff
keys: Change type from PakfireKey to struct pakfire_key
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Jul 2021 16:37:28 +0000 (16:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Jul 2021 16:37:28 +0000 (16:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/key.c
src/_pakfire/key.h
src/_pakfire/pakfire.c
src/libpakfire/archive.c
src/libpakfire/include/pakfire/key.h
src/libpakfire/include/pakfire/types.h
src/libpakfire/key.c
tests/libpakfire/key.c

index 457d34c389fa4975a5853fdd22d3d0f9a3ef6efc..a5e5618650629a67e6a0ecf5b560d66d374cd9ed 100644 (file)
@@ -26,7 +26,7 @@
 #include "key.h"
 #include "pakfire.h"
 
-PyObject* new_key(PyTypeObject* type, PakfireKey key) {
+PyObject* new_key(PyTypeObject* type, struct pakfire_key* key) {
        KeyObject* self = (KeyObject *)type->tp_alloc(type, 0);
        if (self) {
                self->key = pakfire_key_ref(key);
index fa6875acc6d77f3fc650a1f46070738ba93a99d6..fe637f3018ea01fb99f08b1d309ef7c076ea7b15 100644 (file)
 
 typedef struct {
        PyObject_HEAD
-       PakfireKey key;
+       struct pakfire_key* key;
 } KeyObject;
 
 extern PyTypeObject KeyType;
 
-PyObject* new_key(PyTypeObject* type, PakfireKey key);
+PyObject* new_key(PyTypeObject* type, struct pakfire_key* key);
 
 #endif /* PYTHON_PAKFIRE_KEY_H */
index 7a52b25492843d41c770c2cedb38e5321e02d271..a3e307980422a33b568bf149658f9ad9dc56b2aa 100644 (file)
@@ -405,11 +405,11 @@ static PyObject* Pakfire_update(PakfireObject* self, PyObject* args, PyObject* k
        Py_RETURN_NONE;
 }
 
-static PyObject* _import_keylist(PakfireObject* pakfire, PakfireKey* keys) {
+static PyObject* _import_keylist(PakfireObject* pakfire, struct pakfire_key** keys) {
        PyObject* list = PyList_New(0);
 
        while (keys && *keys) {
-               PakfireKey key = *keys++;
+               struct pakfire_key* key = *keys++;
 
                PyObject* object = new_key(&KeyType, key);
                PyList_Append(list, object);
@@ -425,7 +425,7 @@ static PyObject* _import_keylist(PakfireObject* pakfire, PakfireKey* keys) {
 }
 
 static PyObject* Pakfire_get_keys(PakfireObject* self) {
-       PakfireKey* keys = pakfire_key_list(self->pakfire);
+       struct pakfire_key** keys = pakfire_key_list(self->pakfire);
 
        return _import_keylist(self, keys);
 }
@@ -436,7 +436,7 @@ static PyObject* Pakfire_get_key(PakfireObject* self, PyObject* args) {
        if (!PyArg_ParseTuple(args, "s", &pattern))
                return NULL;
 
-       PakfireKey key = pakfire_key_get(self->pakfire, pattern);
+       struct pakfire_key* key = pakfire_key_get(self->pakfire, pattern);
        if (!key)
                Py_RETURN_NONE;
 
@@ -449,7 +449,7 @@ static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args) {
        if (!PyArg_ParseTuple(args, "s", &userid))
                return NULL;
 
-       PakfireKey key = pakfire_key_generate(self->pakfire, userid);
+       struct pakfire_key* key = pakfire_key_generate(self->pakfire, userid);
        assert(key);
 
        return new_key(&KeyType, key);
@@ -461,7 +461,7 @@ static PyObject* Pakfire_import_key(PakfireObject* self, PyObject* args) {
        if (!PyArg_ParseTuple(args, "s", &data))
                return NULL;
 
-       PakfireKey* keys = pakfire_key_import(self->pakfire, data);
+       struct pakfire_key** keys = pakfire_key_import(self->pakfire, data);
        if (!keys)
                return NULL; // TODO Raise error from errno
 
index cf61f932f2d3f7fd6475b67e8b8a83f67c2a8a3d..bb19010929eb8b7f9e7adbe33d2550182a8beaad 100644 (file)
@@ -89,7 +89,7 @@ struct _PakfireArchive {
 
 struct _PakfireArchiveSignature {
        Pakfire pakfire;
-       PakfireKey key;
+       struct pakfire_key* key;
        char* sigdata;
        int nrefs;
 };
index 36111c3196268e91705040900a90e42f0e7908e8..f9d73d03b0cfa7498d1543e6d268c403756b857d 100644 (file)
@@ -24,6 +24,8 @@
 #include <gpgme.h>
 #include <time.h>
 
+struct pakfire_key;
+
 #include <pakfire/types.h>
 
 typedef enum pakfire_key_export_mode {
@@ -31,42 +33,36 @@ typedef enum pakfire_key_export_mode {
        PAKFIRE_KEY_EXPORT_MODE_SECRET,
 } pakfire_key_export_mode_t;
 
-PakfireKey* pakfire_key_list(Pakfire pakfire);
+struct pakfire_key** pakfire_key_list(Pakfire pakfire);
 
-PakfireKey pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey);
-PakfireKey pakfire_key_ref(PakfireKey key);
-void pakfire_key_unref(PakfireKey key);
+struct pakfire_key* pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey);
+struct pakfire_key* pakfire_key_ref(struct pakfire_key* key);
+void pakfire_key_unref(struct pakfire_key* key);
 
-PakfireKey pakfire_key_get(Pakfire pakfire, const char* fingerprint);
-int pakfire_key_delete(PakfireKey key);
+struct pakfire_key* pakfire_key_get(Pakfire pakfire, const char* fingerprint);
+int pakfire_key_delete(struct pakfire_key* key);
 
 // Access key properties
-const char* pakfire_key_get_fingerprint(PakfireKey key);
-const char* pakfire_key_get_uid(PakfireKey key);
-const char* pakfire_key_get_name(PakfireKey key);
-const char* pakfire_key_get_email(PakfireKey key);
-const char* pakfire_key_get_pubkey_algo(PakfireKey key);
-size_t pakfire_key_get_pubkey_length(PakfireKey key);
-time_t pakfire_key_get_created(PakfireKey key);
-time_t pakfire_key_get_expires(PakfireKey key);
-int pakfire_key_is_revoked(PakfireKey key);
+const char* pakfire_key_get_fingerprint(struct pakfire_key* key);
+const char* pakfire_key_get_uid(struct pakfire_key* key);
+const char* pakfire_key_get_name(struct pakfire_key* key);
+const char* pakfire_key_get_email(struct pakfire_key* key);
+const char* pakfire_key_get_pubkey_algo(struct pakfire_key* key);
+size_t pakfire_key_get_pubkey_length(struct pakfire_key* key);
+time_t pakfire_key_get_created(struct pakfire_key* key);
+time_t pakfire_key_get_expires(struct pakfire_key* key);
+int pakfire_key_is_revoked(struct pakfire_key* key);
 
-PakfireKey pakfire_key_generate(Pakfire pakfire, const char* userid);
-char* pakfire_key_export(PakfireKey key, pakfire_key_export_mode_t mode);
-PakfireKey* pakfire_key_import(Pakfire pakfire, const char* data);
+struct pakfire_key* pakfire_key_generate(Pakfire pakfire, const char* userid);
+char* pakfire_key_export(struct pakfire_key* key, pakfire_key_export_mode_t mode);
+struct pakfire_key** pakfire_key_import(Pakfire pakfire, const char* data);
 
-char* pakfire_key_dump(PakfireKey key);
+char* pakfire_key_dump(struct pakfire_key* key);
 
 #ifdef PAKFIRE_PRIVATE
 
 gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire);
 
-struct _PakfireKey {
-       Pakfire pakfire;
-       gpgme_key_t gpgkey;
-       int nrefs;
-};
-
 #endif
 
 #endif /* PAKFIRE_KEY_H */
index a450143b9abe2ab83bb4577b48ebd504d5e12074..97332dc4161886cd34d7506c8ad9922174d2ce14 100644 (file)
@@ -25,6 +25,5 @@ typedef struct _Pakfire* Pakfire;
 typedef struct _PakfireArchive* PakfireArchive;
 typedef struct _PakfireArchiveSignature* PakfireArchiveSignature;
 typedef struct _PakfireFilelist* PakfireFilelist;
-typedef struct _PakfireKey* PakfireKey;
 
 #endif /* PAKFIRE_TYPES_H */
index 64a16f7f25a211fca8da2aee78e3e283c296e6da..9ac9d0a55b351680f7897414252accea04a8b929 100644 (file)
 
 #define DEFAULT_KEY_SIZE "rsa4096"
 
+
+struct pakfire_key {
+       Pakfire pakfire;
+       int nrefs;
+
+       gpgme_key_t gpgkey;
+};
+
 gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire) {
        static int gpg_initialized = 0;
        gpgme_error_t error;
@@ -123,15 +131,15 @@ static size_t pakfire_count_keys(Pakfire pakfire) {
        return count;
 }
 
-PAKFIRE_EXPORT PakfireKey* pakfire_key_list(Pakfire pakfire) {
+PAKFIRE_EXPORT struct pakfire_key** pakfire_key_list(Pakfire pakfire) {
        size_t count = pakfire_count_keys(pakfire);
        if (count == 0)
                return NULL;
 
        gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pakfire);
 
-       PakfireKey* first = calloc(count + 1, sizeof(PakfireKey));
-       PakfireKey* list = first;
+       struct pakfire_key** first = calloc(count + 1, sizeof(struct pakfire_key*));
+       struct pakfire_key** list = first;
 
        gpgme_key_t gpgkey = NULL;
        gpgme_error_t error = gpgme_op_keylist_start(gpgctx, NULL, 0);
@@ -154,8 +162,8 @@ PAKFIRE_EXPORT PakfireKey* pakfire_key_list(Pakfire pakfire) {
        return first;
 }
 
-PAKFIRE_EXPORT PakfireKey pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey) {
-       PakfireKey key = calloc(1, sizeof(*key));
+PAKFIRE_EXPORT struct pakfire_key* pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey) {
+       struct pakfire_key* key = calloc(1, sizeof(*key));
 
        if (key) {
                key->nrefs = 1;
@@ -168,30 +176,30 @@ PAKFIRE_EXPORT PakfireKey pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey
        return key;
 }
 
-static void pakfire_key_free(PakfireKey key) {
+static void pakfire_key_free(struct pakfire_key* key) {
        pakfire_unref(key->pakfire);
        gpgme_key_unref(key->gpgkey);
 
        free(key);
 }
 
-PAKFIRE_EXPORT PakfireKey pakfire_key_ref(PakfireKey key) {
+PAKFIRE_EXPORT struct pakfire_key* pakfire_key_ref(struct pakfire_key* key) {
        ++key->nrefs;
 
        return key;
 }
 
-PAKFIRE_EXPORT void pakfire_key_unref(PakfireKey key) {
+PAKFIRE_EXPORT void pakfire_key_unref(struct pakfire_key* key) {
        if (--key->nrefs > 0)
                return;
 
        pakfire_key_free(key);
 }
 
-static PakfireKey __pakfire_get_key(Pakfire pakfire, gpgme_ctx_t gpgctx, const char* fingerprint) {
+static struct pakfire_key* __pakfire_get_key(Pakfire pakfire, gpgme_ctx_t gpgctx, const char* fingerprint) {
        DEBUG(pakfire, "Seaching for key with fingerprint %s\n", fingerprint);
 
-       PakfireKey key = NULL;
+       struct pakfire_key* key = NULL;
        gpgme_key_t gpgkey = NULL;
 
        gpgme_error_t error = gpgme_get_key(gpgctx, fingerprint, &gpgkey, 0);
@@ -213,16 +221,16 @@ static PakfireKey __pakfire_get_key(Pakfire pakfire, gpgme_ctx_t gpgctx, const c
        return key;
 }
 
-PAKFIRE_EXPORT PakfireKey pakfire_key_get(Pakfire pakfire, const char* fingerprint) {
+PAKFIRE_EXPORT struct pakfire_key* pakfire_key_get(Pakfire pakfire, const char* fingerprint) {
        gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pakfire);
 
-       PakfireKey key = __pakfire_get_key(pakfire, gpgctx, fingerprint);
+       struct pakfire_key* key = __pakfire_get_key(pakfire, gpgctx, fingerprint);
        gpgme_release(gpgctx);
 
        return key;
 }
 
-PAKFIRE_EXPORT int pakfire_key_delete(PakfireKey key) {
+PAKFIRE_EXPORT int pakfire_key_delete(struct pakfire_key* key) {
        gpgme_ctx_t gpgctx = pakfire_get_gpgctx(key->pakfire);
 
        int r = 0;
@@ -235,23 +243,23 @@ PAKFIRE_EXPORT int pakfire_key_delete(PakfireKey key) {
        return r;
 }
 
-PAKFIRE_EXPORT const char* pakfire_key_get_fingerprint(PakfireKey key) {
+PAKFIRE_EXPORT const char* pakfire_key_get_fingerprint(struct pakfire_key* key) {
        return key->gpgkey->fpr;
 }
 
-PAKFIRE_EXPORT const char* pakfire_key_get_uid(PakfireKey key) {
+PAKFIRE_EXPORT const char* pakfire_key_get_uid(struct pakfire_key* key) {
        return key->gpgkey->uids->uid;
 }
 
-PAKFIRE_EXPORT const char* pakfire_key_get_name(PakfireKey key) {
+PAKFIRE_EXPORT const char* pakfire_key_get_name(struct pakfire_key* key) {
        return key->gpgkey->uids->name;
 }
 
-PAKFIRE_EXPORT const char* pakfire_key_get_email(PakfireKey key) {
+PAKFIRE_EXPORT const char* pakfire_key_get_email(struct pakfire_key* key) {
        return key->gpgkey->uids->email;
 }
 
-PAKFIRE_EXPORT const char* pakfire_key_get_pubkey_algo(PakfireKey key) {
+PAKFIRE_EXPORT const char* pakfire_key_get_pubkey_algo(struct pakfire_key* key) {
        switch (key->gpgkey->subkeys->pubkey_algo) {
                case GPGME_PK_RSA:
                case GPGME_PK_RSA_E:
@@ -281,23 +289,23 @@ PAKFIRE_EXPORT const char* pakfire_key_get_pubkey_algo(PakfireKey key) {
        return NULL;
 }
 
-PAKFIRE_EXPORT size_t pakfire_key_get_pubkey_length(PakfireKey key) {
+PAKFIRE_EXPORT size_t pakfire_key_get_pubkey_length(struct pakfire_key* key) {
        return key->gpgkey->subkeys->length;
 }
 
-PAKFIRE_EXPORT time_t pakfire_key_get_created(PakfireKey key) {
+PAKFIRE_EXPORT time_t pakfire_key_get_created(struct pakfire_key* key) {
        return key->gpgkey->subkeys->timestamp;
 }
 
-PAKFIRE_EXPORT time_t pakfire_key_get_expires(PakfireKey key) {
+PAKFIRE_EXPORT time_t pakfire_key_get_expires(struct pakfire_key* key) {
        return key->gpgkey->subkeys->expires;
 }
 
-PAKFIRE_EXPORT int pakfire_key_is_revoked(PakfireKey key) {
+PAKFIRE_EXPORT int pakfire_key_is_revoked(struct pakfire_key* key) {
        return key->gpgkey->subkeys->revoked;
 }
 
-PAKFIRE_EXPORT PakfireKey pakfire_key_generate(Pakfire pakfire, const char* userid) {
+PAKFIRE_EXPORT struct pakfire_key* pakfire_key_generate(Pakfire pakfire, const char* userid) {
        gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pakfire);
 
        unsigned int flags = 0;
@@ -328,7 +336,7 @@ PAKFIRE_EXPORT PakfireKey pakfire_key_generate(Pakfire pakfire, const char* user
        return pakfire_key_get(pakfire, result->fpr);
 }
 
-PAKFIRE_EXPORT char* pakfire_key_export(PakfireKey key, pakfire_key_export_mode_t mode) {
+PAKFIRE_EXPORT char* pakfire_key_export(struct pakfire_key* key, pakfire_key_export_mode_t mode) {
        gpgme_ctx_t gpgctx = pakfire_get_gpgctx(key->pakfire);
 
        gpgme_export_mode_t gpgmode = 0;
@@ -382,7 +390,7 @@ FAIL:
        return NULL;
 }
 
-PAKFIRE_EXPORT PakfireKey* pakfire_key_import(Pakfire pakfire, const char* data) {
+PAKFIRE_EXPORT struct pakfire_key** pakfire_key_import(Pakfire pakfire, const char* data) {
        gpgme_error_t error;
        gpgme_data_t keydata;
 
@@ -411,12 +419,12 @@ PAKFIRE_EXPORT PakfireKey* pakfire_key_import(Pakfire pakfire, const char* data)
                        if (!status)
                                return NULL;
 
-                       PakfireKey* head = calloc(result->imported + 1, sizeof(*head));
-                       PakfireKey* list = head;
+                       struct pakfire_key** head = calloc(result->imported + 1, sizeof(*head));
+                       struct pakfire_key** list = head;
 
                        // Retrieve all imported keys
                        while (status) {
-                               PakfireKey key = __pakfire_get_key(pakfire, gpgctx, status->fpr);
+                               struct pakfire_key* key = __pakfire_get_key(pakfire, gpgctx, status->fpr);
                                if (key) {
                                        const char* fingerprint = pakfire_key_get_fingerprint(key);
                                        INFO(pakfire, "Imported key %s\n", fingerprint);
@@ -454,7 +462,7 @@ FAIL:
        return NULL;
 }
 
-PAKFIRE_EXPORT char* pakfire_key_dump(PakfireKey key) {
+PAKFIRE_EXPORT char* pakfire_key_dump(struct pakfire_key* key) {
        char* s = "";
 
        time_t created = pakfire_key_get_created(key);
index 3905f0fac840a4cf07bdfce32a2ba7927ec9e1c0..b740dd07c8f017f10ce04a825f87e61212c182ca 100644 (file)
@@ -29,9 +29,9 @@
 
 static int test_init(const struct test* t) {
        // Try loading any keys & delete them all
-       PakfireKey* keys = pakfire_key_list(t->pakfire);
+       struct pakfire_key** keys = pakfire_key_list(t->pakfire);
        while (keys && *keys) {
-               PakfireKey key = *keys++;
+               struct pakfire_key* key = *keys++;
 
                pakfire_key_delete(key);
                pakfire_key_unref(key);
@@ -49,14 +49,14 @@ static int test_init(const struct test* t) {
 static int test_import_export(const struct test* t) {
        // Try to delete the key just in case it
        // has been imported before
-       PakfireKey key = pakfire_key_get(t->pakfire, TEST_KEY_FINGERPRINT);
+       struct pakfire_key* key = pakfire_key_get(t->pakfire, TEST_KEY_FINGERPRINT);
        if (key) {
                pakfire_key_delete(key);
                pakfire_key_unref(key);
        }
 
        // Import a key
-       PakfireKey* keys = pakfire_key_import(t->pakfire, TEST_KEY_DATA);
+       struct pakfire_key** keys = pakfire_key_import(t->pakfire, TEST_KEY_DATA);
 
        // We should have a list with precisely one key object
        ASSERT(keys);