summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-02-25 19:03:12 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-25 19:07:15 +0100
commit65b77c941780c8e1819f527879b0b8e2642839dd (patch)
treeca6209c92705e19989d823b6574d4914354aecef /apt-pkg/contrib
parent5dd61ec04ca6b4ccbde1f94ff5f55299ba7fd1fb (diff)
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
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/hashes.cc23
1 files changed, 23 insertions, 0 deletions
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)
{