From 843627b2d3f801a7e9e45af0cc2cd4654077fac8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Jun 2022 08:57:53 +0200 Subject: Add butl::sha256 to types.hxx --- bpkg/auth.cxx | 1 - bpkg/checksum.cxx | 2 +- bpkg/checksum.hxx | 6 ++---- bpkg/database.cxx | 4 +--- bpkg/fetch-pkg.cxx | 10 +++++----- bpkg/manifest-utility.cxx | 1 - bpkg/pkg-build.cxx | 1 - bpkg/pkg-fetch.cxx | 6 +++--- bpkg/rep-create.cxx | 6 +++--- bpkg/rep-info.cxx | 1 - bpkg/types.hxx | 7 +++++++ 11 files changed, 22 insertions(+), 23 deletions(-) diff --git a/bpkg/auth.cxx b/bpkg/auth.cxx index 85cf5fa..663054d 100644 --- a/bpkg/auth.cxx +++ b/bpkg/auth.cxx @@ -7,7 +7,6 @@ #include // numeric_limits #include // ostreambuf_iterator -#include #include #include #include diff --git a/bpkg/checksum.cxx b/bpkg/checksum.cxx index 65ed377..b761d0b 100644 --- a/bpkg/checksum.cxx +++ b/bpkg/checksum.cxx @@ -331,7 +331,7 @@ namespace bpkg } string - sha256 (const common_options& o, const path& f) + sha256sum (const common_options& o, const path& f) { if (!exists (f)) fail << "file " << f << " does not exist"; diff --git a/bpkg/checksum.hxx b/bpkg/checksum.hxx index 73f52e8..54e5b3c 100644 --- a/bpkg/checksum.hxx +++ b/bpkg/checksum.hxx @@ -4,8 +4,6 @@ #ifndef BPKG_CHECKSUM_HXX #define BPKG_CHECKSUM_HXX -#include - #include #include @@ -16,7 +14,7 @@ namespace bpkg // Calculate SHA256 sum of the specified memory buffer in binary mode. // inline string - sha256 (const char* buf, size_t n) {return butl::sha256 (buf, n).string ();} + sha256sum (const char* buf, size_t n) {return sha256 (buf, n).string ();} // The same but for a file. Issue diagnostics and throw failed if anything // goes wrong. @@ -26,7 +24,7 @@ namespace bpkg // optimized for the platform. // string - sha256 (const common_options&, const path& file); + sha256sum (const common_options&, const path& file); } #endif // BPKG_CHECKSUM_HXX diff --git a/bpkg/database.cxx b/bpkg/database.cxx index b0a673e..d96c53b 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -10,8 +10,6 @@ #include #include -#include - #include #include #include @@ -706,7 +704,7 @@ namespace bpkg // std::string schema; { - butl::sha256 h (d.string ()); + sha256 h (d.string ()); for (size_t n (4);; ++n) { diff --git a/bpkg/fetch-pkg.cxx b/bpkg/fetch-pkg.cxx index 64abb43..ca4767f 100644 --- a/bpkg/fetch-pkg.cxx +++ b/bpkg/fetch-pkg.cxx @@ -52,7 +52,7 @@ namespace bpkg is.close (); string s (bs.str ()); - string sha256sum (sha256 (s.c_str (), s.size ())); + string cs (sha256sum (s.c_str (), s.size ())); istringstream ts (s); // Text mode. @@ -60,7 +60,7 @@ namespace bpkg M m (mp, ignore_unknown); if (pr.wait ()) - return make_pair (move (m), move (sha256sum)); + return make_pair (move (m), move (cs)); // Child existed with an error, fall through. } @@ -146,14 +146,14 @@ namespace bpkg // and reading the manifest. The file should be opened in the binary // mode for the first operation and in the text mode for the second one. // - string sha256sum; + string cs; if (o != nullptr) - sha256sum = sha256 (*o, f); // Read file in the binary mode. + cs = sha256sum (*o, f); // Read file in the binary mode. ifdstream ifs (f); // Open file in the text mode. manifest_parser mp (ifs, f.string ()); - return make_pair (M (mp, ignore_unknown), move (sha256sum)); + return make_pair (M (mp, ignore_unknown), move (cs)); } catch (const manifest_parsing& e) { diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index f690a40..d205c2d 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -6,7 +6,6 @@ #include // strcspn() #include -#include #include // wildcard_version #include diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 90e2d70..63bbc36 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -12,7 +12,6 @@ #include // ref() #include -#include #include #include diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx index 531bf84..d065ff1 100644 --- a/bpkg/pkg-fetch.cxx +++ b/bpkg/pkg-fetch.cxx @@ -256,12 +256,12 @@ namespace bpkg // assert (ap->sha256sum); - const string& sha256sum (sha256 (co, a)); - if (sha256sum != *ap->sha256sum) + const string& cs (sha256sum (co, a)); + if (cs != *ap->sha256sum) { fail << "checksum mismatch for " << n << " " << v << info << pl->repository_fragment->name << " has " << *ap->sha256sum << - info << "fetched archive has " << sha256sum << + info << "fetched archive has " << cs << info << "consider re-fetching package list and trying again" << info << "if problem persists, consider reporting this to " << "the repository maintainer"; diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index 13ffbf1..c9ee924 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -106,7 +106,7 @@ namespace bpkg // Calculate its checksum. // - m.sha256sum = sha256 (o, a); + m.sha256sum = sha256sum (o, a); l4 ([&]{trace << m.name << " " << m.version << " in " << a << " sha256sum " << *m.sha256sum;}); @@ -183,7 +183,7 @@ namespace bpkg collect (o, pm, d, d); pkg_package_manifests manifests; - manifests.sha256sum = sha256 (o, path (d / repositories_file)); + manifests.sha256sum = sha256sum (o, path (d / repositories_file)); for (auto& p: pm) { @@ -235,7 +235,7 @@ namespace bpkg info << "run 'bpkg help rep-create' for more information"; signature_manifest m; - m.sha256sum = sha256 (o, p); + m.sha256sum = sha256sum (o, p); m.signature = sign_repository (o, m.sha256sum, key, *cert, d); p = path (d / signature_file); diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx index 5184048..7d78173 100644 --- a/bpkg/rep-info.cxx +++ b/bpkg/rep-info.cxx @@ -5,7 +5,6 @@ #include // cout -#include // sha256_to_fingerprint() #include #include diff --git a/bpkg/types.hxx b/bpkg/types.hxx index a8cd0f4..2b6a1f8 100644 --- a/bpkg/types.hxx +++ b/bpkg/types.hxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include // icase_compare_string, // compare_reference_target @@ -103,6 +104,12 @@ namespace bpkg // using butl::url; + // + // + using butl::sha256; + using butl::sha256_to_fingerprint; + using butl::fingerprint_to_sha256; + // // using butl::process; -- cgit v1.1