From 65b77c941780c8e1819f527879b0b8e2642839dd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 25 Feb 2020 19:03:12 +0100 Subject: Initialize libgcrypt on first use This is not supposed to be done this way, but frankly, since we abstract away the backend, there's not much else we can do here. Closes: #949074 --- apt-pkg/contrib/hashes.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'apt-pkg/contrib/hashes.cc') diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 6afd0815f..8733f6392 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -302,8 +302,30 @@ public: unsigned long long FileSize; gcry_md_hd_t hd; + void maybeInit() + { + + // Yikes, we got to initialize libgcrypt, or we get warnings. But we + // abstract away libgcrypt in Hashes from our users - they are not + // supposed to know what the hashing backend is, so we can't force + // them to init themselves as libgcrypt folks want us to. So this + // only leaves us with this option... + if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P)) + { + if (!gcry_check_version(nullptr)) + { + fprintf(stderr, "libgcrypt is too old (need %s, have %s)\n", + "nullptr", gcry_check_version(NULL)); + exit(2); + } + + gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); + } + } + explicit PrivateHashes(unsigned int const CalcHashes) : FileSize(0) { + maybeInit(); gcry_md_open(&hd, 0, 0); for (auto & Algo : Algorithms) { @@ -313,6 +335,7 @@ public: } explicit PrivateHashes(HashStringList const &Hashes) : FileSize(0) { + maybeInit(); gcry_md_open(&hd, 0, 0); for (auto & Algo : Algorithms) { -- cgit v1.2.3