Libkleo

compat.cpp
1/*
2 utils/compat.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2021 g10 Code GmbH
6 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include <config-libkleo.h>
12
13#include "compat.h"
14
15#include "algorithm.h"
16
17#include <QGpgME/CryptoConfig>
18
19#include <gpgme++/key.h>
20
21using namespace QGpgME;
22
23QGpgME::CryptoConfigEntry *Kleo::getCryptoConfigEntry(const CryptoConfig *config, const char *componentName, const char *entryName)
24{
25 if (!config) {
26 return nullptr;
27 }
28 return config->entry(QString::fromLatin1(componentName), QString::fromLatin1(entryName));
29}
30
31bool Kleo::keyHasCertify(const GpgME::Key &key)
32{
33#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE
34 return key.hasCertify();
35#else
36 return Kleo::any_of(key.subkeys(), [](const auto &subkey) {
37 return subkey.canCertify();
38 });
39#endif
40}
41
42bool Kleo::keyHasSign(const GpgME::Key &key)
43{
44#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE
45 return key.hasSign();
46#else
47 return Kleo::any_of(key.subkeys(), [](const auto &subkey) {
48 return subkey.canSign();
49 });
50#endif
51}
52
53bool Kleo::keyHasEncrypt(const GpgME::Key &key)
54{
55#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE
56 return key.hasEncrypt();
57#else
58 return Kleo::any_of(key.subkeys(), [](const auto &subkey) {
59 return subkey.canEncrypt();
60 });
61#endif
62}
63
64bool Kleo::keyHasAuthenticate(const GpgME::Key &key)
65{
66#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE
67 return key.hasAuthenticate();
68#else
69 return Kleo::any_of(key.subkeys(), [](const auto &subkey) {
70 return subkey.canAuthenticate();
71 });
72#endif
73}
QString fromLatin1(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.