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 <gpgme++/gpgmefw.h>
27#include <gpgme++/result.h>
28#include <gpgme++/gpgme++_export.h>
29
30#include <time.h>
31
32#include <boost/shared_ptr.hpp>
33
34#include <vector>
35#include <iosfwd>
36
37namespace GpgME {
38
39 class Error;
40 class Signature;
41 class Notation;
42
43 class GPGMEPP_EXPORT VerificationResult : public Result {
44 public:
45 VerificationResult();
46 VerificationResult( gpgme_ctx_t ctx, int error );
47 VerificationResult( gpgme_ctx_t ctx, const Error & error );
48 explicit VerificationResult( const Error & err );
49
50 const VerificationResult & operator=( VerificationResult other ) {
51 swap( other );
52 return *this;
53 }
54
55 void swap( VerificationResult & other ) {
56 Result::swap( other );
57 using std::swap;
58 swap( this->d, other.d );
59 }
60
61 bool isNull() const;
62
63 const char * fileName() const;
64
65 unsigned int numSignatures() const;
66 Signature signature( unsigned int index ) const;
67 std::vector<Signature> signatures() const;
68
69 class Private;
70 private:
71 void init( gpgme_ctx_t ctx );
72 boost::shared_ptr<Private> d;
73 };
74
75 GPGMEPP_EXPORT std::ostream & operator<<( std::ostream & os, const VerificationResult & result );
76
77 class GPGMEPP_EXPORT Signature {
78 friend class ::GpgME::VerificationResult;
79 Signature( const boost::shared_ptr<VerificationResult::Private> & parent, unsigned int index );
80 public:
81 typedef GPGMEPP_DEPRECATED GpgME::Notation Notation;
82
83 Signature();
84
85 const Signature & operator=( Signature other ) {
86 swap( other );
87 return *this;
88 }
89
90 void swap( Signature & other ) {
91 using std::swap;
92 swap( this->d, other.d );
93 swap( this->idx, other.idx );
94 }
95
96 bool isNull() const;
97
98
99 enum Summary {
100 None = 0x000,
101 Valid = 0x001,
102 Green = 0x002,
103 Red = 0x004,
104 KeyRevoked = 0x008,
105 KeyExpired = 0x010,
106 SigExpired = 0x020,
107 KeyMissing = 0x040,
108 CrlMissing = 0x080,
109 CrlTooOld = 0x100,
110 BadPolicy = 0x200,
111 SysError = 0x400
112 };
113 Summary summary() const;
114
115 const char * fingerprint() const;
116
117 Error status() const;
118
119 time_t creationTime() const;
120 time_t expirationTime() const;
121 bool neverExpires() const;
122
123 GPGMEPP_DEPRECATED bool wrongKeyUsage() const {
124 return isWrongKeyUsage();
125 }
126 bool isWrongKeyUsage() const;
127 bool isVerifiedUsingChainModel() const;
128
129 enum PKAStatus {
130 UnknownPKAStatus, PKAVerificationFailed, PKAVerificationSucceeded
131 };
132 PKAStatus pkaStatus() const;
133 const char * pkaAddress() const;
134
135 enum Validity {
136 Unknown, Undefined, Never, Marginal, Full, Ultimate
137 };
138 Validity validity() const;
139 char validityAsString() const;
140 Error nonValidityReason() const;
141
142 unsigned int publicKeyAlgorithm() const;
143 const char * publicKeyAlgorithmAsString() const;
144
145 unsigned int hashAlgorithm() const;
146 const char * hashAlgorithmAsString() const;
147
148 const char * policyURL() const;
149 GpgME::Notation notation( unsigned int index ) const;
150 std::vector<GpgME::Notation> notations() const;
151
152 private:
153 boost::shared_ptr<VerificationResult::Private> d;
154 unsigned int idx;
155 };
156
157 GPGMEPP_EXPORT std::ostream & operator<<( std::ostream & os, const Signature & sig );
158 GPGMEPP_EXPORT std::ostream & operator<<( std::ostream & os, Signature::PKAStatus pkaStatus );
159 GPGMEPP_EXPORT std::ostream & operator<<( std::ostream & os, Signature::Summary summary );
160
161}
162
163GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION( VerificationResult )
164GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION( Signature )
165
166#endif // __GPGMEPP_VERIFICATIONRESULT_H__
167