diff --git a/CMakeLists.txt b/CMakeLists.txt index be5464d24..1a3093165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,199 +1,202 @@ # SPDX-License-Identifier: CC0-1.0 # SPDX-FileCopyrightText: none cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(PIM_VERSION "5.24.42") project(libkleo VERSION ${PIM_VERSION}) set(KF_MIN_VERSION "5.105.0") if (WIN32) set(KF5_WANT_VERSION "5.104.0") else () set(KF5_WANT_VERSION ${KF_MIN_VERSION}) endif () find_package(ECM ${KF5_WANT_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMGenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(FeatureSummary) include(ECMQtDeclareLoggingCategory) include(ECMDeprecationSettings) include(ECMAddQch) include(KDEClangFormat) include(KDEGitCommitHooks) option(BUILD_WITH_COMPAT_LIBS "Generate compat cmake file (Set at false will allow to co-install lib)" ON) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") set(LIBKLEO_LIB_VERSION ${PIM_VERSION}) set(QT_REQUIRED_VERSION "5.15.2") if (QT_MAJOR_VERSION STREQUAL "6") set(QT_REQUIRED_VERSION "6.4.0") set(KF_MIN_VERSION "5.240.0") set(KF_MAJOR_VERSION "6") else() set(KF_MAJOR_VERSION "5") endif() set(KDEPIMTEXTEDIT_VERSION "5.24.40") set(GPGME_REQUIRED_VERSION "1.16.0") find_package(Qt${QT_MAJOR_VERSION} ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets) if (QT_MAJOR_VERSION STREQUAL "6") find_package(Qt6Core5Compat) endif() find_package(KF${KF_MAJOR_VERSION}I18n ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}Config ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}WidgetsAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}ConfigWidgets ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}Completion ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}CoreAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}Codecs ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF${KF_MAJOR_VERSION}ItemModels ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KPim${KF_MAJOR_VERSION}TextEdit ${KDEPIMTEXTEDIT_VERSION} CONFIG) find_package(Gpgmepp ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) set_package_properties(Gpgmepp PROPERTIES DESCRIPTION "GpgME++ Library" URL "https://www.gnupg.org" TYPE REQUIRED PURPOSE "GpgME++ is required for OpenPGP support") message(STATUS "GpgME++ Version ${Gpgmepp_VERSION}") if (Gpgmepp_VERSION VERSION_GREATER_EQUAL "1.19.1") set(GPGMEPP_KEY_CANSIGN_IS_FIXED 1) set(GPGMEPP_ERROR_ASSTRING_RETURNS_UTF8_ON_WINDOWS 1) endif() +if (Gpgmepp_VERSION VERSION_GREATER_EQUAL "1.23.0") + set(GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE 1) +endif() set(QGPGME_NAME "QGpgme") find_package(${QGPGME_NAME} ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) if (${QGPGME_NAME}_VERSION VERSION_GREATER_EQUAL "1.18.1") set(QGPGME_LISTALLKEYSJOB_HAS_OPTIONS 1) endif() find_package(Boost 1.34.0) set_package_properties(Boost PROPERTIES DESCRIPTION "Boost C++ Libraries" URL "https://www.boost.org" TYPE REQUIRED PURPOSE "Boost is required for building most KDEPIM applications") set_package_properties(KPim${KF_MAJOR_VERSION}TextEdit PROPERTIES DESCRIPTION "A textedit with PIM-specific features." URL "https://commits.kde.org/kpimtextedit" TYPE OPTIONAL PURPOSE "Improved audit log viewer.") ecm_setup_version(PROJECT VARIABLE_PREFIX LIBKLEO VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/libkleo_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPim${KF_MAJOR_VERSION}LibkleoConfigVersion.cmake" SOVERSION 5 ) ########### Targets ########### ecm_set_disabled_deprecation_versions(QT 5.15.2 KF 5.105.0) remove_definitions(-DQT_NO_FOREACH) add_definitions(-DQT_NO_EMIT) ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KPim${KF_MAJOR_VERSION}Libkleo") set(LIBKLEO_KF5_COMPAT FALSE) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KPimLibkleoConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KPim${KF_MAJOR_VERSION}LibkleoConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KPim${KF_MAJOR_VERSION}LibkleoConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KPim${KF_MAJOR_VERSION}LibkleoConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KPim${KF_MAJOR_VERSION}LibkleoTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KPim${KF_MAJOR_VERSION}LibkleoTargets.cmake NAMESPACE KPim${KF_MAJOR_VERSION}::) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libkleo_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KPim${KF_MAJOR_VERSION}/Libkleo COMPONENT Devel ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-libkleo.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-libkleo.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) option(USE_UNITY_CMAKE_SUPPORT "Use UNITY cmake support (speedup compile time)" OFF) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT OFF) if (USE_UNITY_CMAKE_SUPPORT) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT ON) endif() add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ecm_qt_install_logging_categories( EXPORT LIBKLEO FILE libkleo.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} ) ki18n_install(po) if (BUILD_QCH) ecm_install_qch_export( TARGETS KPim${KF_MAJOR_VERSION}Libkleo_QCH FILE KPim${KF_MAJOR_VERSION}LibkleoQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KPim${KF_MAJOR_VERSION}LibkleoQchTargets.cmake\")") endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT) if (BUILD_WITH_COMPAT_LIBS) #if (QT_MAJOR_VERSION STREQUAL "5") ## # TODO: Backwards compatiblity. Remove in next major version ## set(CMAKECONFIG_INSTALL_DIR_KF5 "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Libkleo") set(LIBKLEO_KF5_COMPAT TRUE) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KPimLibkleoConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkleoConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR_KF5} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkleoConfig.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR_KF5}" COMPONENT Devel ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KPim${KF_MAJOR_VERSION}LibkleoConfigVersion.cmake" RENAME "KF5LibkleoConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR_KF5}" COMPONENT Devel ) install(EXPORT KPim${KF_MAJOR_VERSION}LibkleoTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR_KF5}" FILE KPim${KF_MAJOR_VERSION}LibkleoTargets.cmake NAMESPACE KF5:: ) if (BUILD_QCH) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KPim${KF_MAJOR_VERSION}LibkleoQchTargets.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR_KF5}" COMPONENT Devel ) endif() #endif() endif() diff --git a/config-libkleo.h.cmake b/config-libkleo.h.cmake index 3138caae9..c2ea00919 100644 --- a/config-libkleo.h.cmake +++ b/config-libkleo.h.cmake @@ -1,8 +1,11 @@ /* Defined if QGpgME::ListAllKeysJob supports setting options */ #cmakedefine QGPGME_LISTALLKEYSJOB_HAS_OPTIONS 1 /* Defined if Key::canSign should be used instead of deprecated Key::canReallySign */ #cmakedefine01 GPGMEPP_KEY_CANSIGN_IS_FIXED /* Whether Error::asString() returns UTF-8 encoded strings on Windows */ #cmakedefine01 GPGMEPP_ERROR_ASSTRING_RETURNS_UTF8_ON_WINDOWS + +/* Whether Key::hasCertify(), Key::hasSign(), Key::hasEncrypt(), Key::hasAuthenticate() exist */ +#cmakedefine01 GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE diff --git a/src/utils/compat.cpp b/src/utils/compat.cpp index da58ab720..6c0286ffa 100644 --- a/src/utils/compat.cpp +++ b/src/utils/compat.cpp @@ -1,27 +1,73 @@ /* utils/compat.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "compat.h" +#include "algorithm.h" + #include #include using namespace QGpgME; QGpgME::CryptoConfigEntry *Kleo::getCryptoConfigEntry(const CryptoConfig *config, const char *componentName, const char *entryName) { if (!config) { return nullptr; } return config->entry(QString::fromLatin1(componentName), QString::fromLatin1(entryName)); } + +bool Kleo::keyHasCertify(const GpgME::Key &key) +{ +#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE + return key.hasCertify(); +#else + return Kleo::any_of(key.subkeys(), [](const auto &subkey) { + return subkey.canCertify(); + }); +#endif +} + +bool Kleo::keyHasSign(const GpgME::Key &key) +{ +#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE + return key.hasSign(); +#else + return Kleo::any_of(key.subkeys(), [](const auto &subkey) { + return subkey.canSign(); + }); +#endif +} + +bool Kleo::keyHasEncrypt(const GpgME::Key &key) +{ +#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE + return key.hasEncrypt(); +#else + return Kleo::any_of(key.subkeys(), [](const auto &subkey) { + return subkey.canEncrypt(); + }); +#endif +} + +bool Kleo::keyHasAuthenticate(const GpgME::Key &key) +{ +#if GPGMEPP_KEY_HAS_HASCERTIFY_SIGN_ENCRYPT_AUTHENTICATE + return key.hasAuthenticate(); +#else + return Kleo::any_of(key.subkeys(), [](const auto &subkey) { + return subkey.canAuthenticate(); + }); +#endif +} diff --git a/src/utils/compat.h b/src/utils/compat.h index c486a3dca..99431164c 100644 --- a/src/utils/compat.h +++ b/src/utils/compat.h @@ -1,26 +1,52 @@ /* utils/compat.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "kleo_export.h" +#include + +namespace GpgME +{ +class Key; +} namespace QGpgME { class CryptoConfig; class CryptoConfigEntry; } namespace Kleo { KLEO_EXPORT QGpgME::CryptoConfigEntry *getCryptoConfigEntry(const QGpgME::CryptoConfig *config, const char *componentName, const char *entryName); +/** + * Returns true, if the key has a certification subkey. + * Compatibility function for GpgME::Key::hasCertify() added in GpgME 1.23 + */ +KLEO_EXPORT bool keyHasCertify(const GpgME::Key &key); +/** + * Returns true, if the key has a signing subkey. + * Compatibility function for GpgME::Key::hasSign() added in GpgME 1.23 + */ +KLEO_EXPORT bool keyHasSign(const GpgME::Key &key); +/** + * Returns true, if the key has an encryption subkey. + * Compatibility function for GpgME::Key::hasEncrypt() added in GpgME 1.23 + */ +KLEO_EXPORT bool keyHasEncrypt(const GpgME::Key &key); +/** + * Returns true, if the key has an authentication subkey. + * Compatibility function for GpgME::Key::hasAuthenticate() added in GpgME 1.23 + */ +KLEO_EXPORT bool keyHasAuthenticate(const GpgME::Key &key); }