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

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     ./crypto/sender.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 Sender
0037 {
0038 public:
0039     Sender()
0040         : d()
0041     {
0042     }
0043     explicit Sender(const KMime::Types::Mailbox &mailbox);
0044 
0045     void swap(Sender &other)
0046     {
0047         d.swap(other.d);
0048     }
0049 
0050     bool isNull() const
0051     {
0052         return !d;
0053     }
0054 
0055     bool isSigningAmbiguous(GpgME::Protocol proto) const;
0056     bool isEncryptionAmbiguous(GpgME::Protocol proto) const;
0057 
0058     const KMime::Types::Mailbox &mailbox() const;
0059 
0060     const std::vector<GpgME::Key> &signingCertificateCandidates(GpgME::Protocol proto) const;
0061     const std::vector<GpgME::Key> &encryptToSelfCertificateCandidates(GpgME::Protocol proto) const;
0062 
0063     void setResolvedSigningKey(const GpgME::Key &key);
0064     GpgME::Key resolvedSigningKey(GpgME::Protocol proto) const;
0065 
0066     void setResolvedEncryptionKey(const GpgME::Key &key);
0067     GpgME::Key resolvedEncryptionKey(GpgME::Protocol proto) const;
0068 
0069     void setResolvedOpenPGPEncryptionUserID(const GpgME::UserID &uid);
0070     GpgME::UserID resolvedOpenPGPEncryptionUserID() const;
0071 
0072     friend inline bool operator==(const Sender &lhs, const Sender &rhs)
0073     {
0074         return rhs.d == lhs.d || lhs.deepEquals(rhs);
0075     }
0076 
0077 private:
0078     void detach();
0079     bool deepEquals(const Sender &other) const;
0080 
0081 private:
0082     class Private;
0083     std::shared_ptr<Private> d;
0084 };
0085 
0086 inline bool operator!=(const Sender &lhs, const Sender &rhs)
0087 {
0088     return !operator==(lhs, rhs);
0089 }
0090 
0091 } // namespace Crypto
0092 } // namespace Kleo