File indexing completed on 2024-06-16 04:55:58

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     ./crypto/recipient.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <gpgme++/global.h>
0013 
0014 #include <memory>
0015 #include <vector>
0016 
0017 namespace KMime
0018 {
0019 namespace Types
0020 {
0021 class Mailbox;
0022 }
0023 }
0024 
0025 namespace GpgME
0026 {
0027 class Key;
0028 class UserID;
0029 }
0030 
0031 namespace Kleo
0032 {
0033 namespace Crypto
0034 {
0035 
0036 class Recipient
0037 {
0038 public:
0039     Recipient()
0040         : d()
0041     {
0042     }
0043     explicit Recipient(const KMime::Types::Mailbox &mailbox);
0044 
0045     void swap(Recipient &other)
0046     {
0047         d.swap(other.d);
0048     }
0049 
0050     bool isNull() const
0051     {
0052         return !d;
0053     }
0054 
0055     bool isEncryptionAmbiguous(GpgME::Protocol protocol) const;
0056 
0057     const KMime::Types::Mailbox &mailbox() const;
0058 
0059     const std::vector<GpgME::Key> &encryptionCertificateCandidates(GpgME::Protocol proto) const;
0060 
0061     void setResolvedEncryptionKey(const GpgME::Key &key);
0062     GpgME::Key resolvedEncryptionKey(GpgME::Protocol proto) const;
0063 
0064     void setResolvedOpenPGPEncryptionUserID(const GpgME::UserID &uid);
0065     GpgME::UserID resolvedOpenPGPEncryptionUserID() const;
0066 
0067     friend inline bool operator==(const Recipient &lhs, const Recipient &rhs)
0068     {
0069         return rhs.d == lhs.d || lhs.deepEquals(rhs);
0070     }
0071 
0072 private:
0073     void detach();
0074     bool deepEquals(const Recipient &other) const;
0075 
0076 private:
0077     class Private;
0078     std::shared_ptr<Private> d;
0079 };
0080 
0081 inline bool operator!=(const Recipient &lhs, const Recipient &rhs)
0082 {
0083     return !operator==(lhs, rhs);
0084 }
0085 
0086 } // namespace Crypto
0087 } // namespace Kleo