#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);
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 */
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);
}
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);
}
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;
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);
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
struct _PakfireArchiveSignature {
Pakfire pakfire;
- PakfireKey key;
+ struct pakfire_key* key;
char* sigdata;
int nrefs;
};
#include <gpgme.h>
#include <time.h>
+struct pakfire_key;
+
#include <pakfire/types.h>
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 */
typedef struct _PakfireArchive* PakfireArchive;
typedef struct _PakfireArchiveSignature* PakfireArchiveSignature;
typedef struct _PakfireFilelist* PakfireFilelist;
-typedef struct _PakfireKey* PakfireKey;
#endif /* PAKFIRE_TYPES_H */
#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;
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);
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;
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);
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;
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:
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;
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;
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;
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);
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);
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);
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);