]> git.ipfire.org Git - pakfire.git/commitdiff
keys: Make the ID an array of bytes again
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jun 2023 17:59:45 +0000 (17:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jun 2023 17:59:45 +0000 (17:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/key.c
src/libpakfire/include/pakfire/key.h
src/libpakfire/key.c

index cd0681305ca0f7e01aea69a7883484fb1c6af89b..499cff29f40131e8373145d1c452e5bf857db222 100644 (file)
@@ -53,9 +53,9 @@ static void Key_dealloc(KeyObject* self) {
 }
 
 static PyObject* Key_repr(KeyObject* self) {
-       const pakfire_key_id id = pakfire_key_get_id(self->key);
+       const pakfire_key_id* id = pakfire_key_get_id(self->key);
 
-       return PyUnicode_FromFormat("<_pakfire.Key (%lu)>", id);
+       return PyUnicode_FromFormat("<_pakfire.Key (%lu)>", *id);
 }
 
 static PyObject* Key_str(KeyObject* self) {
@@ -68,9 +68,9 @@ static PyObject* Key_str(KeyObject* self) {
 }
 
 static PyObject* Key_get_id(KeyObject* self) {
-       const pakfire_key_id id = pakfire_key_get_id(self->key);
+       const pakfire_key_id* id = pakfire_key_get_id(self->key);
 
-       return PyLong_FromUnsignedLong(id);
+       return PyLong_FromUnsignedLong(*id);
 }
 
 static PyObject* Key_get_algorithm(KeyObject* self) {
index 96a5352e3dfe14fb4bf099af157284d3de3b3e1f..87b9ad17dac73dc151a7180b88e08c5e63c85d7d 100644 (file)
@@ -37,13 +37,13 @@ typedef enum pakfire_key_export_mode {
        PAKFIRE_KEY_EXPORT_MODE_PRIVATE,
 } pakfire_key_export_mode_t;
 
-typedef uint64_t pakfire_key_id;
+typedef unsigned char pakfire_key_id[8];
 
 struct pakfire_key* pakfire_key_ref(struct pakfire_key* key);
 void pakfire_key_unref(struct pakfire_key* key);
 
 // Access key properties
-pakfire_key_id pakfire_key_get_id(struct pakfire_key* key);
+pakfire_key_id* pakfire_key_get_id(struct pakfire_key* key);
 const char* pakfire_key_get_algo(struct pakfire_key* key);
 
 int pakfire_key_generate(struct pakfire_key** key, struct pakfire* pakfire,
index 9d2ec1e05277887b429e22f09767c146ac01358e..e3d31271ca846131c3074f43c79fee5e3394678b 100644 (file)
@@ -116,7 +116,7 @@ static int pakfire_key_create(struct pakfire_key** key, struct pakfire* pakfire,
        }
 
        // Store the key ID
-       k->id = id;
+       memcpy(k->id, id, sizeof(k->id));
 
        // Keep a reference to this key
        EVP_PKEY_up_ref(pkey);
@@ -153,7 +153,7 @@ PAKFIRE_EXPORT void pakfire_key_unref(struct pakfire_key* key) {
        pakfire_key_free(key);
 }
 
-PAKFIRE_EXPORT pakfire_key_id pakfire_key_get_id(struct pakfire_key* key) {
+PAKFIRE_EXPORT pakfire_key_id* pakfire_key_get_id(struct pakfire_key* key) {
        return key->id;
 }
 
@@ -557,7 +557,7 @@ static int pakfire_key_export_private_key(struct pakfire_key* key,
        }
 
        // Copy the key ID
-       buffer->id = key->id;
+       memcpy(buffer->id, key->id, sizeof(buffer->id));
 
        // Write the public key
        r = pakfire_key_get_public_key(key, buffer->keys.public, sizeof(buffer->keys.public));
@@ -604,7 +604,7 @@ static int pakfire_key_export_public_key(struct pakfire_key* key,
        }
 
        // Copy the key ID
-       buffer->id = key->id;
+       memcpy(buffer->id, key->id, sizeof(buffer->id));
 
        // Write the public key
        r = pakfire_key_get_public_key(key, buffer->pubkey, sizeof(buffer->pubkey));
@@ -789,7 +789,7 @@ static int __pakfire_key_sign(struct pakfire_key* key,
        signature->sig_algo[1] = 'd';
 
        // Set the key ID
-       signature->key_id = key->id;
+       memcpy(signature->key_id, key->id, sizeof(signature->key_id));
 
        // Create a message digest context
        mdctx = EVP_MD_CTX_new();