Cpp / Qt: Reduce boost usage (memory and tuple)
[gpgme.git] / lang / cpp / src / verificationresult.h
1 /*
2   verificationresult.h - wraps a gpgme verify result
3   Copyright (C) 2004 Klarälvdalens Datakonsult AB
4
5   This file is part of GPGME++.
6
7   GPGME++ is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Library General Public
9   License as published by the Free Software Foundation; either
10   version 2 of the License, or (at your option) any later version.
11
12   GPGME++ is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU Library General Public License for more details.
16
17   You should have received a copy of the GNU Library General Public License
18   along with GPGME++; see the file COPYING.LIB.  If not, write to the
19   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20   Boston, MA 02110-1301, USA.
21 */
22
23 #ifndef __GPGMEPP_VERIFICATIONRESULT_H__
24 #define __GPGMEPP_VERIFICATIONRESULT_H__
25
26 #include "gpgmefw.h"
27 #include "result.h"
28 #include "gpgmepp_export.h"
29
30 #include <time.h>
31
32 #include <memory>
33
34 #include <vector>
35 #include <iosfwd>
36
37 namespace GpgME
38 {
39
40 class Error;
41 class Signature;
42 class Notation;
43
44 class GPGMEPP_EXPORT VerificationResult : public Result
45 {
46 public:
47     VerificationResult();
48     VerificationResult(gpgme_ctx_t ctx, int error);
49     VerificationResult(gpgme_ctx_t ctx, const Error &error);
50     explicit VerificationResult(const Error &err);
51
52     const VerificationResult &operator=(VerificationResult other)
53     {
54         swap(other);
55         return *this;
56     }
57
58     void swap(VerificationResult &other)
59     {
60         Result::swap(other);
61         using std::swap;
62         swap(this->d, other.d);
63     }
64
65     bool isNull() const;
66
67     const char *fileName() const;
68
69     unsigned int numSignatures() const;
70     Signature signature(unsigned int index) const;
71     std::vector<Signature> signatures() const;
72
73     class Private;
74 private:
75     void init(gpgme_ctx_t ctx);
76     std::shared_ptr<Private> d;
77 };
78
79 GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const VerificationResult &result);
80
81 class GPGMEPP_EXPORT Signature
82 {
83     friend class ::GpgME::VerificationResult;
84     Signature(const std::shared_ptr<VerificationResult::Private> &parent, unsigned int index);
85 public:
86     typedef GPGMEPP_DEPRECATED GpgME::Notation Notation;
87
88     Signature();
89
90     const Signature &operator=(Signature other)
91     {
92         swap(other);
93         return *this;
94     }
95
96     void swap(Signature &other)
97     {
98         using std::swap;
99         swap(this->d, other.d);
100         swap(this->idx, other.idx);
101     }
102
103     bool isNull() const;
104
105     enum Summary {
106         None       = 0x000,
107         Valid      = 0x001,
108         Green      = 0x002,
109         Red        = 0x004,
110         KeyRevoked = 0x008,
111         KeyExpired = 0x010,
112         SigExpired = 0x020,
113         KeyMissing = 0x040,
114         CrlMissing = 0x080,
115         CrlTooOld  = 0x100,
116         BadPolicy  = 0x200,
117         SysError   = 0x400
118     };
119     Summary summary() const;
120
121     const char *fingerprint() const;
122
123     Error status() const;
124
125     time_t creationTime() const;
126     time_t expirationTime() const;
127     bool neverExpires() const;
128
129     GPGMEPP_DEPRECATED bool wrongKeyUsage() const
130     {
131         return isWrongKeyUsage();
132     }
133     bool isWrongKeyUsage() const;
134     bool isVerifiedUsingChainModel() const;
135
136     enum PKAStatus {
137         UnknownPKAStatus, PKAVerificationFailed, PKAVerificationSucceeded
138     };
139     PKAStatus pkaStatus() const;
140     const char *pkaAddress() const;
141
142     enum Validity {
143         Unknown, Undefined, Never, Marginal, Full, Ultimate
144     };
145     Validity validity() const;
146     char validityAsString() const;
147     Error nonValidityReason() const;
148
149     unsigned int publicKeyAlgorithm() const;
150     const char *publicKeyAlgorithmAsString() const;
151
152     unsigned int hashAlgorithm() const;
153     const char *hashAlgorithmAsString() const;
154
155     const char *policyURL() const;
156     GpgME::Notation notation(unsigned int index) const;
157     std::vector<GpgME::Notation> notations() const;
158
159 private:
160     std::shared_ptr<VerificationResult::Private> d;
161     unsigned int idx;
162 };
163
164 GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Signature &sig);
165 GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Signature::PKAStatus pkaStatus);
166 GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Signature::Summary summary);
167
168 }
169
170 GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(VerificationResult)
171 GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Signature)
172
173 #endif // __GPGMEPP_VERIFICATIONRESULT_H__