File indexing completed on 2024-06-09 05:17:27
0001 /* -*- mode: c++; c-basic-offset:4 -*- 0002 utils/compliance.h 0003 0004 This file is part of libkleopatra 0005 SPDX-FileCopyrightText: 2022 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 #pragma once 0012 0013 #include "kleo_export.h" 0014 0015 #include <string_view> 0016 #include <vector> 0017 0018 class QPushButton; 0019 class QString; 0020 0021 namespace GpgME 0022 { 0023 class Key; 0024 class UserID; 0025 } 0026 0027 namespace Kleo::DeVSCompliance 0028 { 0029 0030 /** 0031 * Returns true, if compliance mode "de-vs" is configured for GnuPG. 0032 * Note: It does not check whether the used GnuPG is actually compliant. 0033 */ 0034 KLEO_EXPORT bool isActive(); 0035 0036 /** 0037 * Returns true, if compliance mode "de-vs" is configured for GnuPG and if 0038 * GnuPG passes a basic compliance check, i.e. at least libgcrypt and the used 0039 * RNG are compliant. 0040 */ 0041 KLEO_EXPORT bool isCompliant(); 0042 0043 /** 0044 * Returns true, if the given algorithm is compliant with compliance mode 0045 * "de-vs". Always returns true, if compliance mode "de-vs" is not active. 0046 */ 0047 KLEO_EXPORT bool algorithmIsCompliant(std::string_view algo); 0048 0049 /** 0050 * Returns true, if all usable subkeys of the key \p key are compliant with 0051 * compliance mode "de-vs". Usable subkeys are those that are neither revoked 0052 * nor expired. If the key doesn't have any usable subkeys, then false is 0053 * returned. 0054 * Always returns true, if compliance mode "de-vs" is not active. 0055 */ 0056 KLEO_EXPORT bool allSubkeysAreCompliant(const GpgME::Key &key); 0057 0058 /** 0059 * Returns true, if the key \p key is compliant with compliance mode "de-vs". 0060 * This function behaves like DeVSCompliance::keyIsCompliant, but only considers 0061 * user id \p id; all other user ids are ignored. 0062 * \see keyIsCompliant 0063 */ 0064 bool userIDIsCompliant(const GpgME::UserID &id); 0065 0066 /** 0067 * Returns true, if the key \p key is compliant with compliance mode "de-vs". 0068 * A key is considered compliant if all usable subkeys are compliant and if 0069 * all not revoked user IDs have at least full validity. The second condition 0070 * requires that the key has been validated. 0071 * Always returns true, if compliance mode "de-vs" is not active. 0072 * 0073 * \see allSubkeysAreCompliant 0074 */ 0075 KLEO_EXPORT bool keyIsCompliant(const GpgME::Key &key); 0076 0077 /** 0078 * Returns a static list of the available compliant algorithms. 0079 */ 0080 KLEO_EXPORT const std::vector<std::string> &compliantAlgorithms(); 0081 0082 /** 0083 * Returns a static list of the preferred compliant algorithms with decreasing 0084 * preference. 0085 * Can be used to determine the default algorithm for generating new keys. 0086 */ 0087 KLEO_EXPORT const std::vector<std::string> &preferredCompliantAlgorithms(); 0088 0089 /** 0090 * \overload 0091 * 0092 * Sets the appropriate icon and, unless high-contrast mode is active, the 0093 * appropriate background color of \p button depending on the state of 0094 * compliance. 0095 */ 0096 KLEO_EXPORT void decorate(QPushButton *button); 0097 0098 /** 0099 * Sets the appropriate icon and, unless high-contrast mode is active, the 0100 * appropriate background color of \p button depending on the value of 0101 * \p compliant. 0102 */ 0103 KLEO_EXPORT void decorate(QPushButton *button, bool compliant); 0104 0105 /** 0106 * \overload 0107 * 0108 * Returns a localized name for the compliance or non-compliance depending on 0109 * the state of compliance. 0110 */ 0111 KLEO_EXPORT QString name(); 0112 0113 /** 0114 * Returns a localized name for the compliance or non-compliance depending on 0115 * the value of \p compliant. 0116 * 0117 * \note The localized name is taken from the de-vs-filter filter resp. the 0118 * not-de-vs-filter. This allows the customization of the name for different 0119 * users because VS-NfD compliance is called differently in different 0120 * environments, e.g. NATO RESTRICTED or EU RESTRICTED. 0121 */ 0122 KLEO_EXPORT QString name(bool compliant); 0123 }