From: Michael Tremer Date: Sat, 1 Feb 2025 15:53:56 +0000 (+0000) Subject: keys: Give signing functions better names X-Git-Tag: 0.9.30~192 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a72c5cd4fe87814c1d15d373f87c975a44b3c29;p=pakfire.git keys: Give signing functions better names Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/key.c b/src/pakfire/key.c index dd555560..ac1c90c4 100644 --- a/src/pakfire/key.c +++ b/src/pakfire/key.c @@ -830,10 +830,10 @@ ERROR: return r; } -int pakfire_key_sign(struct pakfire_key* key, +int pakfire_key_sign_string(struct pakfire_key* key, FILE* f, const void* data, const size_t length, const char* comment) { struct pakfire_key_signature signature = { 0 }; - char* s = NULL; + char* buffer = NULL; int r; // Create a signature @@ -852,12 +852,12 @@ int pakfire_key_sign(struct pakfire_key* key, } // Encode the signature to base64 - r = pakfire_b64encode(key->ctx, &s, &signature, sizeof(signature)); + r = pakfire_b64encode(key->ctx, &buffer, &signature, sizeof(signature)); if (r < 0) goto ERROR; // Write the signature - r = fprintf(f, "%s\n", s); + r = fprintf(f, "%s\n", buffer); if (r < 0) { ERROR(key->ctx, "Could not write the signature: %m\n"); r = -errno; @@ -871,13 +871,13 @@ int pakfire_key_sign(struct pakfire_key* key, r = 0; ERROR: - if (s) - free(s); + if (buffer) + free(buffer); return r; } -int pakfire_key_signf(struct pakfire_key* key, FILE* s, FILE* f, const char* comment) { +int pakfire_key_sign(struct pakfire_key* key, FILE* s, FILE* f, const char* comment) { char* buffer = NULL; size_t length = 0; int r; @@ -888,7 +888,7 @@ int pakfire_key_signf(struct pakfire_key* key, FILE* s, FILE* f, const char* com goto ERROR; // Sign! - r = pakfire_key_sign(key, s, buffer, length, comment); + r = pakfire_key_sign_string(key, s, buffer, length, comment); ERROR: if (buffer) diff --git a/src/pakfire/key.h b/src/pakfire/key.h index f97923e5..959f155b 100644 --- a/src/pakfire/key.h +++ b/src/pakfire/key.h @@ -55,14 +55,13 @@ int pakfire_key_import(struct pakfire_key** key, struct pakfire_ctx* ctx, FILE* char* pakfire_key_dump(struct pakfire_key* key, size_t* length); // Sign -int pakfire_key_sign(struct pakfire_key* key, - FILE* f, const void* data, const size_t length, const char* comment); +int pakfire_key_sign(struct pakfire_key* key, FILE* s, FILE* f, const char* comment); +int pakfire_key_sign_string(struct pakfire_key* key, + FILE* s, const void* data, const size_t length, const char* comment); int pakfire_key_verify(struct pakfire_key* key, FILE* f, const void* data, const size_t length); int pakfire_key_import_from_string(struct pakfire_key** key, struct pakfire_ctx* ctx, const char* data, const size_t length); -int pakfire_key_signf(struct pakfire_key* key, FILE* s, FILE* f, const char* comment); - #endif /* PAKFIRE_KEY_H */ diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index ab3bccd7..aa19f84c 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -1993,7 +1993,7 @@ static int pakfire_repo_sign_database(struct pakfire_repo* repo, struct pakfire_ } // Create the signature - r = pakfire_key_signf(key, s, f, "Database Signature"); + r = pakfire_key_sign(key, s, f, "Database Signature"); if (r) { ERROR(repo->ctx, "Could not sign the database: %m\n"); goto ERROR; diff --git a/src/python/key.c b/src/python/key.c index 03645c45..24bafd1f 100644 --- a/src/python/key.c +++ b/src/python/key.c @@ -177,7 +177,7 @@ static PyObject* Key_sign(KeyObject* self, PyObject* args, PyObject* kwargs) { } // Create the signature - r = pakfire_key_sign(self->key, f, data, data_length, comment); + r = pakfire_key_sign_string(self->key, f, data, data_length, comment); if (r) { PyErr_SetFromErrno(PyExc_OSError); goto ERROR; diff --git a/tests/libpakfire/key.c b/tests/libpakfire/key.c index 32d626a4..5ca1cb62 100644 --- a/tests/libpakfire/key.c +++ b/tests/libpakfire/key.c @@ -75,7 +75,7 @@ static int test_sign_and_verify(const struct test* t) { ASSERT_SUCCESS(pakfire_key_export(key, stdout, PAKFIRE_KEY_EXPORT_MODE_PRIVATE)); // Sign! - ASSERT_SUCCESS(pakfire_key_sign(key, f, DATA, DATA_LENGTH, "UNTRUSTED COMMENT")); + ASSERT_SUCCESS(pakfire_key_sign_string(key, f, DATA, DATA_LENGTH, "UNTRUSTED COMMENT")); // Rewind the file rewind(f);