diff --git a/autotests/abstractkeylistmodeltest.h b/autotests/abstractkeylistmodeltest.h index a2b243b0d..697e5ce9b 100644 --- a/autotests/abstractkeylistmodeltest.h +++ b/autotests/abstractkeylistmodeltest.h @@ -1,40 +1,38 @@ /* autotests/abstractkeylistmodeltest.h This file is part of libkleopatra's test suite. SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef ABSTRACTKEYLISTMODELTEST_H -#define ABSTRACTKEYLISTMODELTEST_H +#pragma once #include namespace Kleo { class AbstractKeyListModel; } class AbstractKeyListModelTest: public QObject { Q_OBJECT private Q_SLOTS: void testCreation(); void testSetKeys(); void testSetGroups(); void testKeys(); void testIndex(); void testIndexForGroup(); void testAddGroup(); void testSetData(); void testRemoveGroup(); void testClear(); private: virtual Kleo::AbstractKeyListModel *createModel() = 0; }; -#endif // ABSTRACTKEYLISTMODELTEST_H diff --git a/src/kleo/checksumdefinition.h b/src/kleo/checksumdefinition.h index 34ea079af..1ca9f8b02 100644 --- a/src/kleo/checksumdefinition.h +++ b/src/kleo/checksumdefinition.h @@ -1,110 +1,108 @@ /* -*- mode: c++; c-basic-offset:4 -*- checksumdefinition.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_CHECKSUMDEFINITION_H__ -#define __KLEO_CHECKSUMDEFINITION_H__ +#pragma once #include "kleo_export.h" #include #include #include #include class QProcess; namespace Kleo { class KLEO_EXPORT ChecksumDefinition { protected: ChecksumDefinition(const QString &id, const QString &label, const QString &outputFileName, const QStringList &extensions); public: virtual ~ChecksumDefinition(); enum ArgumentPassingMethod { CommandLine, NewlineSeparatedInputFile, NullSeparatedInputFile, NumArgumentPassingMethods }; QString id() const { return m_id; } QString label() const { return m_label; } const QStringList &patterns() const { return m_patterns; } QString outputFileName() const { return m_outputFileName; } QString createCommand() const; ArgumentPassingMethod createCommandArgumentPassingMethod() const { return m_createMethod; } QString verifyCommand() const; ArgumentPassingMethod verifyCommandArgumentPassingMethod() const { return m_verifyMethod; } bool startCreateCommand(QProcess *process, const QStringList &files) const; bool startVerifyCommand(QProcess *process, const QStringList &files) const; static QString installPath(); static void setInstallPath(const QString &ip); static std::vector< std::shared_ptr > getChecksumDefinitions(); static std::vector< std::shared_ptr > getChecksumDefinitions(QStringList &errors); static std::shared_ptr getDefaultChecksumDefinition(const std::vector< std::shared_ptr > &available); static void setDefaultChecksumDefinition(const std::shared_ptr &checksumDefinition); protected: void setCreateCommandArgumentPassingMethod(ArgumentPassingMethod method) { m_createMethod = method; } void setVerifyCommandArgumentPassingMethod(ArgumentPassingMethod method) { m_verifyMethod = method; } private: virtual QString doGetCreateCommand() const = 0; virtual QString doGetVerifyCommand() const = 0; virtual QStringList doGetCreateArguments(const QStringList &files) const = 0; virtual QStringList doGetVerifyArguments(const QStringList &files) const = 0; private: const QString m_id; const QString m_label; const QString m_outputFileName; const QStringList m_patterns; ArgumentPassingMethod m_createMethod = CommandLine; ArgumentPassingMethod m_verifyMethod = CommandLine; }; } -#endif /* __KLEO_CHECKSUMDEFINITION_H__ */ diff --git a/src/kleo/debug.h b/src/kleo/debug.h index 8f4fc0ba9..d108f4a81 100644 --- a/src/kleo/debug.h +++ b/src/kleo/debug.h @@ -1,25 +1,23 @@ /* kleo/debug.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 */ -#ifndef LIBKLEO_DEBUG_H -#define LIBKLEO_DEBUG_H +#pragma once #include "kleo_export.h" namespace Kleo { class KeyGroup; } class QDebug; KLEO_EXPORT QDebug operator<<(QDebug debug, const Kleo::KeyGroup &group); -#endif // LIBKLEO_DEBUG_H diff --git a/src/kleo/defaultkeyfilter.h b/src/kleo/defaultkeyfilter.h index f2d442efd..edba64a01 100644 --- a/src/kleo/defaultkeyfilter.h +++ b/src/kleo/defaultkeyfilter.h @@ -1,138 +1,136 @@ /* defaultkeyfilter.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik SPDX-FileContributor: Intevation GmbH SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_DEFAULTKEYFILTER_H__ -#define __KLEO_DEFAULTKEYFILTER_H__ +#pragma once #include "keyfilter.h" #include "kleo_export.h" #include #include #include #include #include namespace Kleo { /** Default implementation of key filter class. */ class KLEO_EXPORT DefaultKeyFilter : public KeyFilter { public: DefaultKeyFilter(); ~DefaultKeyFilter() override; /** Used for bool checks */ enum TriState { DoesNotMatter = 0, Set = 1, NotSet = 2 }; /** Used for level checks */ enum LevelState { LevelDoesNotMatter = 0, Is = 1, IsNot = 2, IsAtLeast = 3, IsAtMost = 4 }; bool matches(const GpgME::Key &key, MatchContexts ctx) const override; unsigned int specificity() const override; void setSpecificity(unsigned int value) const; QString id() const override; void setId(const QString &value) const; KeyFilter::MatchContexts availableMatchContexts() const override; void setMatchContexts(KeyFilter::MatchContexts value) const; QColor fgColor() const override; void setFgColor(const QColor &value) const; QColor bgColor() const override; void setBgColor(const QColor &value) const; FontDescription fontDescription() const override; QString name() const override; void setName(const QString &value) const; QString icon() const override; void setIcon(const QString &value) const; QFont font() const; void setFont(const QFont &value) const; TriState revoked() const; TriState expired() const; TriState invalid() const; TriState disabled() const; TriState root() const; TriState canEncrypt() const; TriState canSign() const; TriState canCertify() const; TriState canAuthenticate() const; TriState qualified() const; TriState cardKey() const; TriState hasSecret() const; TriState isOpenPGP() const; TriState wasValidated() const; TriState isDeVS() const; TriState isBad() const; LevelState ownerTrust() const; GpgME::Key::OwnerTrust ownerTrustReferenceLevel() const; LevelState validity() const; GpgME::UserID::Validity validityReferenceLevel() const; bool italic() const; bool bold() const; bool strikeOut() const; bool useFullFont() const; void setRevoked(const TriState) const; void setExpired(const TriState) const; void setInvalid(const TriState) const; void setDisabled(const TriState) const; void setRoot(const TriState) const; void setCanEncrypt(const TriState) const; void setCanSign(const TriState) const; void setCanCertify(const TriState) const; void setCanAuthenticate(const TriState) const; void setQualified(const TriState) const; void setCardKey(const TriState) const; void setHasSecret(const TriState) const; void setIsOpenPGP(const TriState) const; void setWasValidated(const TriState) const; void setIsDeVs(const TriState) const; void setIsBad(const TriState) const; void setOwnerTrust(const LevelState) const; void setOwnerTrustReferenceLevel(const GpgME::Key::OwnerTrust) const; void setValidity(const LevelState) const; void setValidityReferenceLevel(const GpgME::UserID::Validity) const; void setItalic(bool value) const; void setBold(bool value) const; void setStrikeOut(bool value) const; void setUseFullFont(bool value) const; private: class Private; const QScopedPointer d_ptr; }; } // namespace Kleo -#endif diff --git a/src/kleo/defaultkeygenerationjob.h b/src/kleo/defaultkeygenerationjob.h index ccea771e5..64f67a9ee 100644 --- a/src/kleo/defaultkeygenerationjob.h +++ b/src/kleo/defaultkeygenerationjob.h @@ -1,64 +1,62 @@ /* This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2016 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef LIBKLEO_DEFAULTKEYGENERATIONJOB_H -#define LIBKLEO_DEFAULTKEYGENERATIONJOB_H +#pragma once #include #include namespace GpgME { class KeyGenerationResult; } namespace Kleo { /** * Generates a PGP RSA/2048 bit key pair for given name and email address. * * @since 5.4 */ class KLEO_EXPORT DefaultKeyGenerationJob : public QGpgME::Job { Q_OBJECT public: explicit DefaultKeyGenerationJob(QObject *parent = nullptr); ~DefaultKeyGenerationJob() override; /** * Set key passphrase * * Use this method to specify custom passphrase, including an empty * one. If no passphrase (not even empty) is specified, gpg me will * automatically prompt for passphrase using Pinentry dialog. */ void setPassphrase(const QString &passphrase); GpgME::Error start(const QString &email, const QString &name); QString auditLogAsHtml() const override; GpgME::Error auditLogError() const override; public Q_SLOTS: void slotCancel() override; Q_SIGNALS: void result(const GpgME::KeyGenerationResult &result, const QByteArray &pubkeyData, const QString &auditLogAsHtml, const GpgME::Error &auditLogError); protected: bool eventFilter(QObject *watched, QEvent *event) override; private: class Private; Private * const d; }; } -#endif diff --git a/src/kleo/dn.h b/src/kleo/dn.h index 7d51b8207..3f1f52bad 100644 --- a/src/kleo/dn.h +++ b/src/kleo/dn.h @@ -1,140 +1,138 @@ /* dn.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_DN_H__ -#define __KLEO_DN_H__ +#pragma once #include "kleo_export.h" #include #include #include class QWidget; namespace Kleo { class DNAttributeOrderConfigWidget; } namespace Kleo { /** @short DN Attribute mapper */ class KLEO_EXPORT DNAttributeMapper { DNAttributeMapper(); ~DNAttributeMapper(); public: static const DNAttributeMapper *instance(); QString name2label(const QString &s) const; QStringList names() const; const QStringList &attributeOrder() const; void setAttributeOrder(const QStringList &order); DNAttributeOrderConfigWidget *configWidget(QWidget *parent = nullptr) const; private: class Private; Private *d; static DNAttributeMapper *mSelf; }; /** @short DN parser and reorderer */ class KLEO_EXPORT DN { public: class Attribute; using AttributeList = QVector; using const_iterator = AttributeList::const_iterator; DN(); explicit DN(const QString &dn); explicit DN(const char *utf8DN); DN(const DN &other); ~DN(); const DN &operator=(const DN &other); /** @return the value in rfc-2253-escaped form */ static QString escape(const QString &value); /** @return the DN in a reordered form, according to the settings in the [DN] group of the application's config file */ QString prettyDN() const; /** @return the DN in the original form */ QString dn() const; /** \overload Uses \a sep as separator (default: ,) */ QString dn(const QString &sep) const; QString operator[](const QString &attr) const; void append(const Attribute &attr); const_iterator begin() const; const_iterator end() const; private: void detach(); private: class Private; Private *d; }; class KLEO_EXPORT DN::Attribute { public: using List = DN::AttributeList; explicit Attribute(const QString &name = QString(), const QString &value = QString()) : mName(name.toUpper()), mValue(value) {} Attribute(const Attribute &other) : mName(other.name()), mValue(other.value()) {} const Attribute &operator=(const Attribute &other) { if (this != &other) { mName = other.name(); mValue = other.value(); } return *this; } const QString &name() const { return mName; } const QString &value() const { return mValue; } void setValue(const QString &value) { mValue = value; } private: QString mName; QString mValue; }; } -#endif // __KLEO_DN_H__ diff --git a/src/kleo/enum.h b/src/kleo/enum.h index 236c5cfbc..30d40078b 100644 --- a/src/kleo/enum.h +++ b/src/kleo/enum.h @@ -1,89 +1,87 @@ /* kleo/enum.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_ENUM_H__ -#define __KLEO_ENUM_H__ +#pragma once #include "kleo_export.h" class QString; #include namespace GpgME { class Key; class UserID; } namespace Kleo { enum CryptoMessageFormat { InlineOpenPGPFormat = 1, OpenPGPMIMEFormat = 2, SMIMEFormat = 4, SMIMEOpaqueFormat = 8, AnyOpenPGP = InlineOpenPGPFormat | OpenPGPMIMEFormat, AnySMIME = SMIMEOpaqueFormat | SMIMEFormat, AutoFormat = AnyOpenPGP | AnySMIME }; KLEO_EXPORT QString cryptoMessageFormatToLabel(CryptoMessageFormat f); KLEO_EXPORT const char *cryptoMessageFormatToString(CryptoMessageFormat f); KLEO_EXPORT QStringList cryptoMessageFormatsToStringList(unsigned int f); KLEO_EXPORT CryptoMessageFormat stringToCryptoMessageFormat(const QString &s); KLEO_EXPORT unsigned int stringListToCryptoMessageFormats(const QStringList &sl); enum Action { Conflict, DoIt, DontDoIt, Ask, AskOpportunistic, Impossible }; enum EncryptionPreference { UnknownPreference = 0, NeverEncrypt = 1, AlwaysEncrypt = 2, AlwaysEncryptIfPossible = 3, AlwaysAskForEncryption = 4, AskWheneverPossible = 5, MaxEncryptionPreference = AskWheneverPossible }; KLEO_EXPORT QString encryptionPreferenceToLabel(EncryptionPreference pref); KLEO_EXPORT const char *encryptionPreferenceToString(EncryptionPreference pref); KLEO_EXPORT EncryptionPreference stringToEncryptionPreference(const QString &str); enum SigningPreference { UnknownSigningPreference = 0, NeverSign = 1, AlwaysSign = 2, AlwaysSignIfPossible = 3, AlwaysAskForSigning = 4, AskSigningWheneverPossible = 5, MaxSigningPreference = AskSigningWheneverPossible }; KLEO_EXPORT QString signingPreferenceToLabel(SigningPreference pref); KLEO_EXPORT const char *signingPreferenceToString(SigningPreference pref); KLEO_EXPORT SigningPreference stringToSigningPreference(const QString &str); enum TrustLevel { Level0, Level1, Level2, Level3, Level4 }; KLEO_EXPORT TrustLevel trustLevel(const GpgME::Key &key); KLEO_EXPORT TrustLevel trustLevel(const GpgME::UserID &uid); } -#endif // __KLEO_CRYPTOBACKEND_H__ diff --git a/src/kleo/kconfigbasedkeyfilter.h b/src/kleo/kconfigbasedkeyfilter.h index c30712788..44adf37bb 100644 --- a/src/kleo/kconfigbasedkeyfilter.h +++ b/src/kleo/kconfigbasedkeyfilter.h @@ -1,28 +1,26 @@ /* kconfigbasedkeyfilter.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_KCONFIGBASEDKEYFILTER_H__ -#define __KLEO_KCONFIGBASEDKEYFILTER_H__ +#pragma once #include "defaultkeyfilter.h" class KConfigGroup; namespace Kleo { class KLEO_EXPORT KConfigBasedKeyFilter : public DefaultKeyFilter { public: explicit KConfigBasedKeyFilter(const KConfigGroup &group); }; } -#endif // __KLEO_KCONFIGBASEDKEYFILTER_H__ diff --git a/src/kleo/keyfilter.h b/src/kleo/keyfilter.h index 36994c64f..edb0b596d 100644 --- a/src/kleo/keyfilter.h +++ b/src/kleo/keyfilter.h @@ -1,98 +1,96 @@ /* keyfilter.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_KEYFILTER_H__ -#define __KLEO_KEYFILTER_H__ +#pragma once #include #include #include namespace GpgME { class Key; } class QFont; class QColor; class QString; namespace Kleo { /** @short An abstract base class key filters */ class KLEO_EXPORT KeyFilter { public: virtual ~KeyFilter() {} enum MatchContext { NoMatchContext = 0x0, Appearance = 0x1, Filtering = 0x2, AnyMatchContext = Appearance | Filtering }; Q_DECLARE_FLAGS(MatchContexts, MatchContext) virtual bool matches(const GpgME::Key &key, MatchContexts ctx) const = 0; virtual unsigned int specificity() const = 0; virtual QString id() const = 0; virtual MatchContexts availableMatchContexts() const = 0; // not sure if we want these here, but for the time being, it's // the easiest way: virtual QColor fgColor() const = 0; virtual QColor bgColor() const = 0; virtual QString name() const = 0; virtual QString icon() const = 0; class FontDescription { public: FontDescription(); FontDescription(const FontDescription &other); FontDescription &operator=(const FontDescription &other) { FontDescription copy(other); swap(copy); return *this; } ~FontDescription(); static FontDescription create(bool bold, bool italic, bool strikeOut); static FontDescription create(const QFont &font, bool bold, bool italic, bool strikeOut); QFont font(const QFont &base) const; FontDescription resolve(const FontDescription &other) const; void swap(FontDescription &other) { std::swap(this->d, other.d); } struct Private; private: Private *d; }; virtual FontDescription fontDescription() const = 0; }; Q_DECLARE_OPERATORS_FOR_FLAGS(KeyFilter::MatchContexts) } -#endif // __KLEO_KEYFILTER_H__ diff --git a/src/kleo/keyfiltermanager.h b/src/kleo/keyfiltermanager.h index 65cdb3164..52738232d 100644 --- a/src/kleo/keyfiltermanager.h +++ b/src/kleo/keyfiltermanager.h @@ -1,69 +1,67 @@ /* keyfiltermanager.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_KEYFILTERMANAGER_H__ -#define __KLEO_KEYFILTERMANAGER_H__ +#pragma once #include "kleo_export.h" #include #include #include #include namespace GpgME { class Key; } class QAbstractItemModel; class QModelIndex; class QFont; class QColor; class QIcon; namespace Kleo { class KLEO_EXPORT KeyFilterManager : public QObject { Q_OBJECT protected: explicit KeyFilterManager(QObject *parent = nullptr); ~KeyFilterManager(); public: static KeyFilterManager *instance(); const std::shared_ptr &filterMatching(const GpgME::Key &key, KeyFilter::MatchContexts contexts) const; std::vector> filtersMatching(const GpgME::Key &key, KeyFilter::MatchContexts contexts) const; QAbstractItemModel *model() const; const std::shared_ptr &keyFilterByID(const QString &id) const; const std::shared_ptr &fromModelIndex(const QModelIndex &mi) const; QModelIndex toModelIndex(const std::shared_ptr &kf) const; void reload(); QFont font(const GpgME::Key &key, const QFont &baseFont) const; QColor bgColor(const GpgME::Key &key) const; QColor fgColor(const GpgME::Key &key) const; QIcon icon(const GpgME::Key &key) const; class Private; private: Private *d; static KeyFilterManager *mSelf; }; } -#endif // __KLEO_KEYFILTERMANAGER_H__ diff --git a/src/kleo/keygroup.h b/src/kleo/keygroup.h index 4e409f120..ccbbea679 100644 --- a/src/kleo/keygroup.h +++ b/src/kleo/keygroup.h @@ -1,81 +1,79 @@ /* kleo/keygroup.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 */ -#ifndef LIBKLEO_KEYGROUP_H -#define LIBKLEO_KEYGROUP_H +#pragma once #include "kleo_export.h" #include #include #include #include class QString; namespace GpgME { class Key; } namespace Kleo { class KLEO_EXPORT KeyGroup { public: typedef QString Id; typedef std::set> Keys; enum Source { UnknownSource, ApplicationConfig, GnuPGConfig, Tags }; KeyGroup(); ~KeyGroup(); explicit KeyGroup(Id id, const QString &name, const std::vector &keys, Source source); KeyGroup(const KeyGroup &other); KeyGroup &operator=(const KeyGroup &other); KeyGroup(KeyGroup &&other); KeyGroup &operator=(KeyGroup &&other); bool isNull() const; Id id() const; Source source() const; void setName(const QString &name); QString name() const; void setKeys(const Keys &keys); void setKeys(const std::vector &keys); const Keys &keys() const; void setIsImmutable(bool isImmutable); bool isImmutable() const; bool insert(const GpgME::Key &key); bool erase(const GpgME::Key &key); private: class Private; std::unique_ptr d; }; } -#endif // LIBKLEO_KEYGROUP_H diff --git a/src/kleo/keyresolver.h b/src/kleo/keyresolver.h index 1c1dd988e..2518f34b9 100644 --- a/src/kleo/keyresolver.h +++ b/src/kleo/keyresolver.h @@ -1,202 +1,200 @@ /* -*- c++ -*- keyresolver.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2018 Intevation GmbH SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_KEYRESOLVER_H__ -#define __KLEO_KEYRESOLVER_H__ +#pragma once #include "kleo_export.h" #include #include #include #include #include #include #include #include namespace GpgME { class Key; } namespace Kleo { /** * Class to find Keys for E-Mail encryption. * * The KeyResolver uses the Keycache to find keys for signing * or encryption. * * Overrides can be provided for address book integration if the * format is not Auto overrides will only be respected if they * match the format provided in the constructor. * * If no override key is provided for an address the key * with a uid that matches the address and has the highest * validity is used. If both keys have the same validity * the newest subkey is used. * * The KeyResolver also supports groups so the number of * encryption keys does not necessarily * need to match the amount of sender addresses. For this reason * maps are used heavily to map: * * CryptoFormat * - Addresses * -- For each Address a List of Keys * * As a caller you should iterate over the CryptoFormats and * send one message for each format for the recipients and signed * by the signing keys. * * If the CryptoMessageFormat is Auto the minimum number * of CryptoMessageFormats is returned that respects all overrides. * * ----- * Planned: * * As the central place to manage mail encryption / signing keys * the Keyresolver will also show various warning / nagging messages * and offer solutions if nagging is not explicitly turned off. * These include: * * - If own keys or subkeys are about to expire: * Offer to extend their expiration date. * * - (S/MIME) If they are about to expire: Offer * to generate a new CSR. * * - If a user has not marked a key as backed up and * uses it for encryption for several mails. * * - If a user has multiple keys for a sender address and they * are not cross signed. Offer to cross sign / publish. */ class KLEO_EXPORT KeyResolver : public QObject { Q_OBJECT public: /** Creates a new key resolver object. * * @param encrypt: Should encryption keys be selected. * @param sign: Should signing keys be selected. * @param format: A specific key protocol (OpenPGP, S/MIME) for selection. Default: Both protocols. * @param allowMixed: Specify if multiple message formats may be resolved. **/ explicit KeyResolver(bool encrypt, bool sign, GpgME::Protocol format = GpgME::UnknownProtocol, bool allowMixed = true); ~KeyResolver() override; /** * Set the list of recipient addresses. Also looks * up possible keys, but doesn't interact with the user. * * @param addresses: A list of unnormalized addresses */ void setRecipients(const QStringList &addresses); /** * Set the senders address. * * Sender address will be added to encryption keys and used * for signing key resolution if the signing keys are not * explicitly set through setSigningKeys. * * @param sender: The sender of this message. */ void setSender(const QString &sender); /** * Set up possible override keys for recipients / sender * addresses. The keys for the fingerprints are looked * up and used when found. Does not interact with the user. * * @param overrides: A map of \ -> (\ \) */ void setOverrideKeys(const QMap > &overrides); /** * Set explicit signing keys. If this was set for a * protocol the sender address will be only used as an additional encryption * recipient for that protocol. */ void setSigningKeys(const QStringList &fingerprints); /** * Set the minimum user id validity for autoresolution. * * The default value is marginal * * @param validity int representation of a GpgME::UserID::Validity. */ void setMinimumValidity(int validity); /** * Get the encryption keys after resolution. * * @return the resolved sender / key pairs for encryption by format. */ QMap > > encryptionKeys() const; /** * Get the signing keys to use after resolution. * * @return the resolved resolved sender / key pairs for signing * by format. */ QMap > signingKeys() const; /** * Starts the key resolving procedure. Emits keysResolved on success or * error. * * @param showApproval: If set to true a dialog listing the keys * will always be shown. * @param parentWidget: Optional, a Widget to use as parent for dialogs. */ void start(bool showApproval, QWidget *parentWidget = nullptr); /** * Set window flags for a possible dialog. */ void setDialogWindowFlags(Qt::WindowFlags flags); /** * Set the protocol that is preferred to be displayed first when * it is not clear from the keys. E.g. if both OpenPGP and S/MIME * can be resolved. */ void setPreferredProtocol(GpgME::Protocol proto); Q_SIGNALS: /** * Emitted when key resolution finished. * * @param success: The general result. If true continue sending, * if false abort. * @param sendUnencrypted: If there could be no key found for one of * the recipients the user was queried if the * mail should be sent out unencrypted. * sendUnencrypted is true if the user agreed * to this.*/ void keysResolved(bool success, bool sendUnencrypted); private: class Private; std::unique_ptr d; }; } // namespace Kleo -#endif // __KLEO_KEYRESOLVER_H__ diff --git a/src/kleo/keyresolvercore.h b/src/kleo/keyresolvercore.h index f212b84f0..490d1c69d 100644 --- a/src/kleo/keyresolvercore.h +++ b/src/kleo/keyresolvercore.h @@ -1,72 +1,70 @@ /* -*- c++ -*- kleo/keyresolvercore.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2018 Intevation GmbH SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __LIBKLEO_KEYRESOLVERCORE_H__ -#define __LIBKLEO_KEYRESOLVERCORE_H__ +#pragma once #include "kleo_export.h" #include #include #include #include class QString; class QStringList; namespace GpgME { class Key; } namespace Kleo { class KLEO_EXPORT KeyResolverCore { public: explicit KeyResolverCore(bool encrypt, bool sign, GpgME::Protocol format = GpgME::UnknownProtocol); ~KeyResolverCore(); void setSender(const QString &sender); QString normalizedSender() const; void setRecipients(const QStringList &addresses); void setSigningKeys(const QStringList &fingerprints); void setOverrideKeys(const QMap > &overrides); void setAllowMixedProtocols(bool allowMixed); void setPreferredProtocol(GpgME::Protocol proto); void setMinimumValidity(int validity); bool resolve(); QMap > signingKeys() const; QMap > > encryptionKeys() const; QStringList unresolvedRecipients(GpgME::Protocol protocol) const; private: class Private; std::unique_ptr d; }; } // namespace Kleo -#endif // __LIBKLEO_KEYRESOLVER_H__ diff --git a/src/kleo/kleoexception.h b/src/kleo/kleoexception.h index 63e69a48b..b6d11dad1 100644 --- a/src/kleo/kleoexception.h +++ b/src/kleo/kleoexception.h @@ -1,59 +1,57 @@ /* -*- mode: c++; c-basic-offset:4 -*- exception.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_EXCEPTION_H__ -#define __KLEO_EXCEPTION_H__ +#pragma once #include "kleo_export.h" #include #include #include namespace Kleo { class KLEO_EXPORT Exception : public GpgME::Exception { public: Exception(gpg_error_t e, const std::string &msg, Options opt = NoOptions) : GpgME::Exception(GpgME::Error(e), msg, opt) {} Exception(gpg_error_t e, const char *msg, Options opt = NoOptions) : GpgME::Exception(GpgME::Error(e), msg, opt) {} Exception(gpg_error_t e, const QString &msg, Options opt = NoOptions) : GpgME::Exception(GpgME::Error(e), msg.toLocal8Bit().constData(), opt) {} Exception(const GpgME::Error &e, const std::string &msg) : GpgME::Exception(e, msg) {} Exception(const GpgME::Error &e, const char *msg) : GpgME::Exception(e, msg) {} Exception(const GpgME::Error &e, const QString &msg) : GpgME::Exception(e, msg.toLocal8Bit().constData()) {} ~Exception() throw (); const std::string &messageLocal8Bit() const { return GpgME::Exception::message(); } gpg_error_t error_code() const { return error().encodedError(); } QString message() const { return QString::fromLocal8Bit(GpgME::Exception::message().c_str()); } }; } -#endif /* __KLEO_EXCEPTION_H__ */ diff --git a/src/kleo/oidmap.h b/src/kleo/oidmap.h index 83b51db57..e4b39a49b 100644 --- a/src/kleo/oidmap.h +++ b/src/kleo/oidmap.h @@ -1,41 +1,39 @@ /* oidmap.h This file is part of libkleo, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEO_OIDMAP_H__ -#define __KLEO_OIDMAP_H__ +#pragma once #include "kleo_export.h" class QString; static const struct { const char *name; const char *oid; } oidmap[] = { // keep them ordered by oid: { "SP", "ST" }, // hack to show the Sphinx-required/desired SP for // StateOrProvince, otherwise known as ST or even S { "NameDistinguisher", "0.2.262.1.10.7.20" }, { "EMAIL", "1.2.840.113549.1.9.1" }, { "SN", "2.5.4.4" }, { "SerialNumber", "2.5.4.5" }, { "T", "2.5.4.12" }, { "D", "2.5.4.13" }, { "BC", "2.5.4.15" }, { "ADDR", "2.5.4.16" }, { "PC", "2.5.4.17" }, { "GN", "2.5.4.42" }, { "Pseudo", "2.5.4.65" }, }; static const unsigned int numOidMaps = sizeof oidmap / sizeof * oidmap; KLEO_EXPORT const char *oidForAttributeName(const QString &attr); -#endif // __KLEO_OIDMAP_H__ diff --git a/src/kleo/predicates.h b/src/kleo/predicates.h index ebad33317..7e70a16bd 100644 --- a/src/kleo/predicates.h +++ b/src/kleo/predicates.h @@ -1,189 +1,187 @@ /* -*- mode: c++; c-basic-offset:4 -*- models/predicates.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __KLEOPATRA_MODELS_PREDICATES_H__ -#define __KLEOPATRA_MODELS_PREDICATES_H__ +#pragma once #include #include #include #include #include #include namespace Kleo { namespace _detail { inline int mystrcmp(const char *s1, const char *s2) { using namespace std; return s1 ? s2 ? strcmp(s1, s2) : 1 : s2 ? -1 : 0; } #define make_comparator_str_impl( Name, expr, cmp ) \ template