File indexing completed on 2025-01-05 04:55:51
0001 /* 0002 utils/compat.cpp 0003 0004 This file is part of libkleopatra, the KDE keymanagement library 0005 SPDX-FileCopyrightText: 2021 g10 Code GmbH 0006 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include <config-libkleo.h> 0012 0013 #include "compat.h" 0014 0015 #include "algorithm.h" 0016 0017 #include <QGpgME/CryptoConfig> 0018 0019 #include <gpgme++/key.h> 0020 0021 using namespace QGpgME; 0022 0023 QGpgME::CryptoConfigEntry *Kleo::getCryptoConfigEntry(const CryptoConfig *config, const char *componentName, const char *entryName) 0024 { 0025 if (!config) { 0026 return nullptr; 0027 } 0028 return config->entry(QString::fromLatin1(componentName), QString::fromLatin1(entryName)); 0029 } 0030 0031 bool Kleo::keyHasCertify(const GpgME::Key &key) 0032 { 0033 #if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE 0034 return key.hasCertify(); 0035 #else 0036 return Kleo::any_of(key.subkeys(), [](const auto &subkey) { 0037 return subkey.canCertify(); 0038 }); 0039 #endif 0040 } 0041 0042 bool Kleo::keyHasSign(const GpgME::Key &key) 0043 { 0044 #if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE 0045 return key.hasSign(); 0046 #else 0047 return Kleo::any_of(key.subkeys(), [](const auto &subkey) { 0048 return subkey.canSign(); 0049 }); 0050 #endif 0051 } 0052 0053 bool Kleo::keyHasEncrypt(const GpgME::Key &key) 0054 { 0055 #if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE 0056 return key.hasEncrypt(); 0057 #else 0058 return Kleo::any_of(key.subkeys(), [](const auto &subkey) { 0059 return subkey.canEncrypt(); 0060 }); 0061 #endif 0062 } 0063 0064 bool Kleo::keyHasAuthenticate(const GpgME::Key &key) 0065 { 0066 #if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE 0067 return key.hasAuthenticate(); 0068 #else 0069 return Kleo::any_of(key.subkeys(), [](const auto &subkey) { 0070 return subkey.canAuthenticate(); 0071 }); 0072 #endif 0073 }