Commit 622af9c5 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Allow restricting the key lookup by keygrip to OpenPGP or S/MIME keys

GnuPG-bug-id: 5126
parent 02030e20
Pipeline #41322 failed with stage
in 8 minutes and 35 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.16.40")
set(PIM_VERSION "5.16.41")
project(libkleo VERSION ${PIM_VERSION})
......
......@@ -463,20 +463,29 @@ std::vector<Key> KeyCache::findByKeyIDOrFingerprint(const std::vector<std::strin
return result;
}
const Subkey &KeyCache::findSubkeyByKeyGrip(const char *grip) const
const Subkey &KeyCache::findSubkeyByKeyGrip(const char *grip, Protocol protocol) const
{
const std::vector<Subkey>::const_iterator it = d->find_keygrip(grip);
if (it == d->by.keygrip.end()) {
static const Subkey null;
static const Subkey null;
d->ensureCachePopulated();
const auto range = std::equal_range(d->by.keygrip.begin(), d->by.keygrip.end(),
grip, _detail::ByKeyGrip<std::less>());
if (range.first == d->by.keygrip.end()) {
return null;
} else if (protocol == UnknownProtocol) {
return *range.first;
} else {
return *it;
for (auto it = range.first; it != range.second; ++it) {
if (it->parent().protocol() == protocol) {
return *it;
}
}
}
return null;
}
const Subkey &KeyCache::findSubkeyByKeyGrip(const std::string &grip) const
const Subkey &KeyCache::findSubkeyByKeyGrip(const std::string &grip, Protocol protocol) const
{
return findSubkeyByKeyGrip(grip.c_str());
return findSubkeyByKeyGrip(grip.c_str(), protocol);
}
std::vector<Subkey> KeyCache::findSubkeysByKeyID(const std::vector<std::string> &ids) const
......
......@@ -105,8 +105,8 @@ public:
std::vector<GpgME::Key> findByKeyIDOrFingerprint(const std::vector<std::string> &ids) const;
const GpgME::Subkey &findSubkeyByKeyGrip(const char *grip) const;
const GpgME::Subkey &findSubkeyByKeyGrip(const std::string &grip) const;
const GpgME::Subkey &findSubkeyByKeyGrip(const char *grip, GpgME::Protocol protocol = GpgME::UnknownProtocol) const;
const GpgME::Subkey &findSubkeyByKeyGrip(const std::string &grip, GpgME::Protocol protocol = GpgME::UnknownProtocol) const;
std::vector<GpgME::Subkey> findSubkeysByKeyID(const std::vector<std::string> &ids) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment