From: Michael Tremer Date: Tue, 21 Sep 2021 10:51:11 +0000 (+0000) Subject: Unify digest enums in packages and downloader X-Git-Tag: 0.9.28~964 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cea394cbfc2728d4cf26bf54a8e5ce0eff212f5;p=pakfire.git Unify digest enums in packages and downloader Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index b6b4dc9c1..63639f9e2 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -193,8 +193,8 @@ static void Package_set_uuid(PackageObject* self, PyObject* value) { pakfire_package_set_uuid(self->package, uuid); } -static PyObject* Package_get_hexdigest(PackageObject* self, enum pakfire_package_digests type) { - enum pakfire_package_digests digest = PAKFIRE_PACKAGE_DIGEST_NONE; +static PyObject* Package_get_hexdigest(PackageObject* self, enum pakfire_digests type) { + enum pakfire_digests digest = PAKFIRE_DIGEST_NONE; const char* hexdigest = pakfire_package_get_hexdigest(self->package, &digest); if (!hexdigest) @@ -208,26 +208,26 @@ static PyObject* Package_get_hexdigest(PackageObject* self, enum pakfire_package } static PyObject* Package_get_hexdigest_sha256(PackageObject* self) { - return Package_get_hexdigest(self, PAKFIRE_PACKAGE_DIGEST_SHA256); + return Package_get_hexdigest(self, PAKFIRE_DIGEST_SHA256); } static PyObject* Package_get_hexdigest_sha512(PackageObject* self) { - return Package_get_hexdigest(self, PAKFIRE_PACKAGE_DIGEST_SHA512); + return Package_get_hexdigest(self, PAKFIRE_DIGEST_SHA512); } static int Package_set_hexdigest(PackageObject* self, - enum pakfire_package_digests type, PyObject* value) { + enum pakfire_digests type, PyObject* value) { const char* hexdigest = PyUnicode_FromValue(value); return pakfire_package_set_hexdigest(self->package, type, hexdigest); } static int Package_set_hexdigest_sha256(PackageObject* self, PyObject* value) { - return Package_set_hexdigest(self, PAKFIRE_PACKAGE_DIGEST_SHA256, value); + return Package_set_hexdigest(self, PAKFIRE_DIGEST_SHA256, value); } static int Package_set_hexdigest_sha512(PackageObject* self, PyObject* value) { - return Package_set_hexdigest(self, PAKFIRE_PACKAGE_DIGEST_SHA512, value); + return Package_set_hexdigest(self, PAKFIRE_DIGEST_SHA512, value); } static PyObject* Package_get_summary(PackageObject* self) { diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index c58d1c0fe..e12791659 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -1871,18 +1871,18 @@ PAKFIRE_EXPORT ssize_t pakfire_archive_get_size(struct pakfire_archive* archive) } static int pakfire_archive_calculate_digest(struct pakfire_archive* archive, - enum pakfire_package_digests digest, unsigned char* output, size_t* length) { + enum pakfire_digests digest, unsigned char* output, size_t* length) { int r = 1; const EVP_MD* md = NULL; // Select hash function switch (digest) { - case PAKFIRE_PACKAGE_DIGEST_SHA512: + case PAKFIRE_DIGEST_SHA512: md = EVP_sha512(); break; - case PAKFIRE_PACKAGE_DIGEST_SHA256: + case PAKFIRE_DIGEST_SHA256: md = EVP_sha256(); break; @@ -1959,7 +1959,7 @@ PAKFIRE_EXPORT int pakfire_archive_make_package(struct pakfire_archive* archive, int r; // Calculate digest - r = pakfire_archive_calculate_digest(archive, PAKFIRE_PACKAGE_DIGEST_SHA512, + r = pakfire_archive_calculate_digest(archive, PAKFIRE_DIGEST_SHA512, digest, &digest_length); if (r) return r; @@ -2151,7 +2151,7 @@ PAKFIRE_EXPORT int pakfire_archive_make_package(struct pakfire_archive* archive, } // Set digests - pakfire_package_set_digest(pkg, PAKFIRE_PACKAGE_DIGEST_SHA512, digest); + pakfire_package_set_digest(pkg, PAKFIRE_DIGEST_SHA512, digest); *package = pkg; diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index 0dc703d38..48b63a43d 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -1096,11 +1096,11 @@ int pakfire_db_add_package(struct pakfire_db* db, goto ROLLBACK; } - enum pakfire_package_digests digest = PAKFIRE_PACKAGE_DIGEST_NONE; + enum pakfire_digests digest = PAKFIRE_DIGEST_NONE; const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest); switch (digest) { - case PAKFIRE_PACKAGE_DIGEST_SHA512: + case PAKFIRE_DIGEST_SHA512: r = sqlite3_bind_text(stmt, 8, hexdigest, -1, NULL); if (r) { ERROR(db->pakfire, "Could not bind digest_sha512: %s\n", sqlite3_errmsg(db->handle)); @@ -1108,14 +1108,14 @@ int pakfire_db_add_package(struct pakfire_db* db, } break; - case PAKFIRE_PACKAGE_DIGEST_SHA256: + case PAKFIRE_DIGEST_SHA256: r = sqlite3_bind_text(stmt, 9, hexdigest, -1, NULL); if (r) { ERROR(db->pakfire, "Could not bind digest_sha256: %s\n", sqlite3_errmsg(db->handle)); goto ROLLBACK; } - case PAKFIRE_PACKAGE_DIGEST_NONE: + case PAKFIRE_DIGEST_NONE: break; } @@ -1429,13 +1429,13 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r // Digest SHA512 const char* digest_sha512 = (const char*)sqlite3_column_text(stmt, 8); if (digest_sha512) { - pakfire_package_set_hexdigest(pkg, PAKFIRE_PACKAGE_DIGEST_SHA512, digest_sha512); + pakfire_package_set_hexdigest(pkg, PAKFIRE_DIGEST_SHA512, digest_sha512); } // Digest SHA256 const char* digest_sha256 = (const char*)sqlite3_column_text(stmt, 9); if (digest_sha256) { - pakfire_package_set_hexdigest(pkg, PAKFIRE_PACKAGE_DIGEST_SHA256, digest_sha256); + pakfire_package_set_hexdigest(pkg, PAKFIRE_DIGEST_SHA256, digest_sha256); } // License diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 622c8cca4..dc9fd9f52 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -251,7 +251,7 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa // Download the file if it does not exist in the cache if (access(cache_path, R_OK) != 0) { r = pakfire_downloader_retrieve(downloader, BASEURL, mirrorlist, - NULL, filename, cache_path, PAKFIRE_DOWNLOADER_MD_NONE, NULL, 0, 0); + NULL, filename, cache_path, PAKFIRE_DIGEST_NONE, NULL, 0, 0); if (r) return r; } diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index 44a4cf7cc..5c01f53da 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -260,7 +260,7 @@ static int debug_callback(CURL *handle, curl_infotype type, static struct pakfire_transfer* pakfire_downloader_create_transfer( struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, const char* url, const char* path, - enum pakfire_downloader_message_digest md, const char* expected_digest, const size_t expected_digest_length, + enum pakfire_digests md, const char* expected_digest, const size_t expected_digest_length, enum pakfire_transfer_flags flags) { struct pakfire_config* config = NULL; @@ -279,7 +279,7 @@ static struct pakfire_transfer* pakfire_downloader_create_transfer( // Check if expected digest is set switch (md) { - case PAKFIRE_DOWNLOADER_MD_NONE: + case PAKFIRE_DIGEST_NONE: break; default: @@ -345,15 +345,15 @@ static struct pakfire_transfer* pakfire_downloader_create_transfer( // Set message digest switch (md) { - case PAKFIRE_DOWNLOADER_MD_SHA512: + case PAKFIRE_DIGEST_SHA512: transfer->md = EVP_sha512(); break; - case PAKFIRE_DOWNLOADER_MD_SHA256: + case PAKFIRE_DIGEST_SHA256: transfer->md = EVP_sha256(); break; - case PAKFIRE_DOWNLOADER_MD_NONE: + case PAKFIRE_DIGEST_NONE: break; } @@ -408,7 +408,7 @@ ERROR: int pakfire_downloader_add_transfer(struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, - const char* url, const char* path, enum pakfire_downloader_message_digest md, + const char* url, const char* path, enum pakfire_digests md, const char* expected_digest, const size_t expected_digest_length, enum pakfire_transfer_flags flags) { struct pakfire_transfer* transfer = pakfire_downloader_create_transfer( @@ -881,7 +881,7 @@ AGAIN: int pakfire_downloader_retrieve(struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, - const char* url, const char* path, enum pakfire_downloader_message_digest md, + const char* url, const char* path, enum pakfire_digests md, const char* expected_digest, const size_t expected_digest_length, enum pakfire_transfer_flags flags) { struct pakfire_transfer* transfer = pakfire_downloader_create_transfer( diff --git a/src/libpakfire/include/pakfire/downloader.h b/src/libpakfire/include/pakfire/downloader.h index 72df9d6cc..6fea6e5cd 100644 --- a/src/libpakfire/include/pakfire/downloader.h +++ b/src/libpakfire/include/pakfire/downloader.h @@ -34,12 +34,6 @@ enum pakfire_transfer_flags { PAKFIRE_TRANSFER_NOTEMP = (1 << 1), }; -enum pakfire_downloader_message_digest { - PAKFIRE_DOWNLOADER_MD_NONE = 0, - PAKFIRE_DOWNLOADER_MD_SHA256, - PAKFIRE_DOWNLOADER_MD_SHA512, -}; - int pakfire_downloader_create(struct pakfire_downloader** downloader, struct pakfire* pakfire); struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* downloader); @@ -47,12 +41,12 @@ struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* d int pakfire_downloader_retrieve(struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, - const char* url, const char* path, enum pakfire_downloader_message_digest md, + const char* url, const char* path, enum pakfire_digests md, const char* expected_digest, const size_t expected_digest_length, enum pakfire_transfer_flags flags); int pakfire_downloader_add_transfer(struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, - const char* url, const char* path, enum pakfire_downloader_message_digest md, + const char* url, const char* path, enum pakfire_digests md, const char* expected_digest, const size_t expected_digest_length, enum pakfire_transfer_flags flags); diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index aebc85ef5..58857324d 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -30,12 +30,6 @@ struct pakfire_package; #include #include -enum pakfire_package_digests { - PAKFIRE_PACKAGE_DIGEST_NONE = 0, - PAKFIRE_PACKAGE_DIGEST_SHA256 = 1 << 0, - PAKFIRE_PACKAGE_DIGEST_SHA512 = 1 << 1, -}; - struct pakfire_package* pakfire_package_create(struct pakfire* pakfire, struct pakfire_repo* repo, const char* name, const char* evr, const char* arch); @@ -58,13 +52,13 @@ void pakfire_package_set_arch(struct pakfire_package* pkg, const char* arch); const char* pakfire_package_get_uuid(struct pakfire_package* pkg); void pakfire_package_set_uuid(struct pakfire_package* pkg, const char* uuid); const unsigned char* pakfire_package_get_digest(struct pakfire_package* pkg, - enum pakfire_package_digests* type); + enum pakfire_digests* type); const char* pakfire_package_get_hexdigest(struct pakfire_package* pkg, - enum pakfire_package_digests* type); + enum pakfire_digests* type); int pakfire_package_set_digest(struct pakfire_package* pkg, - enum pakfire_package_digests type, const unsigned char* digest); + enum pakfire_digests type, const unsigned char* digest); int pakfire_package_set_hexdigest(struct pakfire_package* pkg, - enum pakfire_package_digests type, const char* hexdigest); + enum pakfire_digests type, const char* hexdigest); const char* pakfire_package_get_summary(struct pakfire_package* pkg); void pakfire_package_set_summary(struct pakfire_package* pkg, const char* summary); const char* pakfire_package_get_description(struct pakfire_package* pkg); diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 24a4157bb..ee0a60f04 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -29,6 +29,12 @@ struct pakfire; +enum pakfire_digests { + PAKFIRE_DIGEST_NONE = 0, + PAKFIRE_DIGEST_SHA256 = 1 << 0, + PAKFIRE_DIGEST_SHA512 = 1 << 1, +}; + #include #include #include diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index beeeaf1bd..f91a19db5 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -375,20 +375,20 @@ PAKFIRE_EXPORT void pakfire_package_set_uuid(struct pakfire_package* pkg, const pakfire_package_set_string(pkg, SOLVABLE_PKGID, uuid); } -static enum pakfire_package_digests pakfire_package_id2digest(Id id) { +static enum pakfire_digests pakfire_package_id2digest(Id id) { switch (id) { case REPOKEY_TYPE_SHA512: - return PAKFIRE_PACKAGE_DIGEST_SHA512; + return PAKFIRE_DIGEST_SHA512; case REPOKEY_TYPE_SHA256: - return PAKFIRE_PACKAGE_DIGEST_SHA256; + return PAKFIRE_DIGEST_SHA256; } - return PAKFIRE_PACKAGE_DIGEST_NONE; + return PAKFIRE_DIGEST_NONE; } PAKFIRE_EXPORT const unsigned char* pakfire_package_get_digest( - struct pakfire_package* pkg, enum pakfire_package_digests* type) { + struct pakfire_package* pkg, enum pakfire_digests* type) { Solvable* s = get_solvable(pkg); Id id; @@ -405,7 +405,7 @@ PAKFIRE_EXPORT const unsigned char* pakfire_package_get_digest( } PAKFIRE_EXPORT const char* pakfire_package_get_hexdigest( - struct pakfire_package* pkg, enum pakfire_package_digests* type) { + struct pakfire_package* pkg, enum pakfire_digests* type) { Solvable* s = get_solvable(pkg); Id id; @@ -422,18 +422,18 @@ PAKFIRE_EXPORT const char* pakfire_package_get_hexdigest( } PAKFIRE_EXPORT int pakfire_package_set_digest(struct pakfire_package* pkg, - enum pakfire_package_digests type, const unsigned char* digest) { + enum pakfire_digests type, const unsigned char* digest) { Solvable* s = get_solvable(pkg); Pool* pool = s->repo->pool; Id id; int r = 1; switch (type) { - case PAKFIRE_PACKAGE_DIGEST_SHA256: + case PAKFIRE_DIGEST_SHA256: id = REPOKEY_TYPE_SHA256; break; - case PAKFIRE_PACKAGE_DIGEST_SHA512: + case PAKFIRE_DIGEST_SHA512: id = REPOKEY_TYPE_SHA512; break; @@ -459,15 +459,15 @@ ERROR: return r; } -static size_t pakfire_package_digest_length(enum pakfire_package_digests digest) { +static size_t pakfire_digest_length(enum pakfire_digests digest) { switch (digest) { - case PAKFIRE_PACKAGE_DIGEST_SHA512: + case PAKFIRE_DIGEST_SHA512: return 64; - case PAKFIRE_PACKAGE_DIGEST_SHA256: + case PAKFIRE_DIGEST_SHA256: return 32; - case PAKFIRE_PACKAGE_DIGEST_NONE: + case PAKFIRE_DIGEST_NONE: return 0; } @@ -475,8 +475,8 @@ static size_t pakfire_package_digest_length(enum pakfire_package_digests digest) } PAKFIRE_EXPORT int pakfire_package_set_hexdigest(struct pakfire_package* pkg, - enum pakfire_package_digests type, const char* hexdigest) { - size_t digest_length = pakfire_package_digest_length(type); + enum pakfire_digests type, const char* hexdigest) { + const size_t digest_length = pakfire_digest_length(type); if (!digest_length) { errno = EINVAL; @@ -573,7 +573,7 @@ PAKFIRE_EXPORT void pakfire_package_set_maintainer(struct pakfire_package* pkg, static int pakfire_package_make_cache_path(struct pakfire_package* pkg) { const char* filename = pakfire_package_get_filename(pkg); - enum pakfire_package_digests digest = PAKFIRE_PACKAGE_DIGEST_NONE; + enum pakfire_digests digest = PAKFIRE_DIGEST_NONE; const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest); if (!hexdigest || strlen(hexdigest) < 3) @@ -1018,20 +1018,20 @@ PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags if (build_id) pakfire_package_dump_add_line(&string, _("Build ID"), build_id); - enum pakfire_package_digests digest = PAKFIRE_PACKAGE_DIGEST_NONE; + enum pakfire_digests digest = PAKFIRE_DIGEST_NONE; // Digest const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest); switch (digest) { - case PAKFIRE_PACKAGE_DIGEST_SHA512: + case PAKFIRE_DIGEST_SHA512: pakfire_package_dump_add_line(&string, _("SHA512 Digest"), hexdigest); break; - case PAKFIRE_PACKAGE_DIGEST_SHA256: + case PAKFIRE_DIGEST_SHA256: pakfire_package_dump_add_line(&string, _("SHA256 Digest"), hexdigest); break; - case PAKFIRE_PACKAGE_DIGEST_NONE: + case PAKFIRE_DIGEST_NONE: break; } diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index ce8d7b1d7..35321943c 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -86,7 +86,7 @@ static int pakfire_repo_is_internal(struct pakfire_repo* repo) { } static int pakfire_repo_retrieve(struct pakfire_repo* repo, const char* title, - const char* url, const char* path, enum pakfire_downloader_message_digest md, + const char* url, const char* path, enum pakfire_digests md, const char* expected_digest, const size_t expected_digest_length, enum pakfire_transfer_flags flags) { struct pakfire_downloader* downloader; @@ -122,7 +122,7 @@ static int pakfire_repo_import_key(struct pakfire_repo* repo, const char* url) { // Try to download the key int r = pakfire_repo_retrieve(repo, NULL, url, path, - PAKFIRE_DOWNLOADER_MD_NONE, NULL, 0, PAKFIRE_TRANSFER_NOTEMP|PAKFIRE_TRANSFER_NOPROGRESS); + PAKFIRE_DIGEST_NONE, NULL, 0, PAKFIRE_TRANSFER_NOTEMP|PAKFIRE_TRANSFER_NOPROGRESS); if (r) goto ERROR; @@ -280,7 +280,7 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo, const char* pakfire_string_format(database_url, "repodata/%s", database); return pakfire_repo_retrieve(repo, title, database_url, cache_path, - PAKFIRE_DOWNLOADER_MD_NONE, NULL, 0, 0); + PAKFIRE_DIGEST_NONE, NULL, 0, 0); } static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* path, int refresh) { @@ -371,7 +371,7 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int return pakfire_repo_retrieve(repo, NULL, repo->appdata->mirrorlist_url, repo->appdata->mirrorlist, - PAKFIRE_DOWNLOADER_MD_NONE, NULL, 0, PAKFIRE_TRANSFER_NOPROGRESS); + PAKFIRE_DIGEST_NONE, NULL, 0, PAKFIRE_TRANSFER_NOPROGRESS); } static int pakfire_repo_refresh_metadata(struct pakfire_repo* repo, const int force) { @@ -386,7 +386,7 @@ static int pakfire_repo_refresh_metadata(struct pakfire_repo* repo, const int fo } int r = pakfire_repo_retrieve(repo, NULL, - "repodata/repomd.json", repo->appdata->metadata, PAKFIRE_DOWNLOADER_MD_NONE, + "repodata/repomd.json", repo->appdata->metadata, PAKFIRE_DIGEST_NONE, NULL, 0, PAKFIRE_TRANSFER_NOPROGRESS); if (r) return r; diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index 0a46de3a4..35708dec3 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -457,7 +457,7 @@ static int pakfire_request_add_url(struct pakfire_request* request, int action, // Download the file r = pakfire_downloader_retrieve(downloader, NULL, NULL, NULL, - url, path, PAKFIRE_DOWNLOADER_MD_NONE, NULL, 0, PAKFIRE_TRANSFER_NOTEMP); + url, path, PAKFIRE_DIGEST_NONE, NULL, 0, PAKFIRE_TRANSFER_NOTEMP); if (r) goto ERROR; diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 04e9628ec..4bacfe1dd 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -1019,7 +1019,7 @@ static int pakfire_transaction_download_package(struct pakfire_transaction* tran // Add transfer to downloader r = pakfire_downloader_add_transfer(downloader, baseurl, mirrorlist, - nevra, filename, path, PAKFIRE_DOWNLOADER_MD_NONE, NULL, 0, 0); + nevra, filename, path, PAKFIRE_DIGEST_NONE, NULL, 0, 0); ERROR: if (mirrorlist)