summaryrefslogtreecommitdiffstats
path: root/libtdenetwork/gpgmepp/key.h
blob: 4bbd24be28d652475cc4cd8ab82215105f77cdba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* key.h - wraps a gpgme key
   Copyright (C) 2003 Klarälvdalens Datakonsult AB

   This file is part of GPGME++.
 
   GPGME++ is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
 
   GPGME++ is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GPGME; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
#ifndef __GPGMEPP_KEY_H__
#define __GPGMEPP_KEY_H__

#include <gpgmepp/gpgmefw.h>
#include <gpgmepp/context.h>

#include <sys/time.h>

#include <vector>
#include <kdemacros.h>

namespace GpgME {

  class Subkey;
  class UserID;

  //
  // class Key
  //

  class KDE_EXPORT Key {
    friend class Context;
  public:
    Key();
    Key( gpgme_key_t key, bool acquireRef, unsigned int keyListMode=0 );
    Key( const Key & key );
    ~Key();

    static Key null;

    const Key & operator=( const Key & other );

    bool isNull() const;

    UserID userID( unsigned int index ) const;
    Subkey subkey( unsigned int index ) const;

    unsigned int numUserIDs() const;
    unsigned int numSubkeys() const;

    std::vector<UserID> userIDs() const;
    std::vector<Subkey> subkeys() const;

    bool isRevoked() const;
    bool isExpired() const;
    bool isDisabled() const;
    bool isInvalid() const;

    bool canEncrypt() const;
    bool canSign() const;
    bool canCertify() const;
    bool canAuthenticate() const;

    bool hasSecret() const;
    bool isSecret() const { return hasSecret(); }

    /*!
      @return true if this is a X.509 root certificate (currently
      equivalent to something like
      strcmp( chainID(), subkey(0).fingerprint() ) == 0 )
    */
    bool isRoot() const;

    enum OwnerTrust { Unknown=0, Undefined=1, Never=2,
		    Marginal=3, Full=4, Ultimate=5 };

    OwnerTrust ownerTrust() const;
    char ownerTrustAsString() const;

    typedef Context::Protocol Protocol;
    Protocol protocol() const;
    const char * protocolAsString() const;

    const char * issuerSerial() const;
    const char * issuerName() const;
    const char * chainID() const;

    const char * keyID() const;
    const char * shortKeyID() const;
    const char * primaryFingerprint() const;

    typedef Context::KeyListMode KeyListMode;
    unsigned int keyListMode() const;

  private:
    gpgme_key_t impl() const;
    class Private;
    Private * d;
  };

  //
  // class Subkey
  //

  class KDE_EXPORT Subkey {
  public:
    Subkey( gpgme_key_t key=0, gpgme_sub_key_t subkey=0 );
    Subkey( gpgme_key_t key, unsigned int idx );
    Subkey( const Subkey & other );
    ~Subkey();

    const Subkey & operator=( const Subkey & other );

    bool isNull() const;

    Key parent() const;

    const char * keyID() const;
    const char * fingerprint() const;

    time_t creationTime() const;
    time_t expirationTime() const;
    bool neverExpires() const;

    bool isRevoked() const;
    bool isExpired() const;
    bool isInvalid() const;
    bool isDisabled() const;

    bool canEncrypt() const;
    bool canSign() const;
    bool canCertify() const;
    bool canAuthenticate() const;

    bool isSecret() const;

    unsigned int publicKeyAlgorithm() const;
    const char * publicKeyAlgorithmAsString() const;

    unsigned int length() const;

  private:
    class Private;
    Private * d;
  };

  //
  // class UserID
  //

  class KDE_EXPORT UserID {
  public:
    class Signature;

    UserID( gpgme_key_t key=0, gpgme_user_id_t uid=0 );
    UserID( gpgme_key_t key, unsigned int idx );
    UserID( const UserID & other );
    ~UserID();

    const UserID & operator=( const UserID & other );

    bool isNull() const;

    Key parent() const;

    unsigned int numSignatures() const;
    Signature signature( unsigned int index ) const;
    std::vector<Signature> signatures() const;

    const char * id() const;
    const char * name() const;
    const char * email() const;
    const char * comment() const;

    enum Validity { Unknown=0, Undefined=1, Never=2,
		    Marginal=3, Full=4, Ultimate=5 };

    Validity validity() const;
    char validityAsString() const;

    bool isRevoked() const;
    bool isInvalid() const;

  private:
    class Private;
    Private * d;
  };

  //
  // class UserID::Signature
  //

  class KDE_EXPORT UserID::Signature {
  public:
    class Notation;

    Signature( gpgme_key_t key=0, gpgme_user_id_t uid=0, gpgme_key_sig_t sig=0 );
    Signature( gpgme_key_t key, gpgme_user_id_t uid, unsigned int idx );
    Signature( const Signature & other );
    ~Signature();

    const Signature & operator=( const Signature & other );

    bool isNull() const;

    UserID parent() const;

    const char * signerKeyID() const;

    const char * algorithmAsString() const;
    unsigned int algorithm() const;
    time_t creationTime() const;
    time_t expirationTime() const;
    bool neverExpires() const;

    bool isRevokation() const;
    bool isInvalid() const;
    bool isExpired() const;
    bool isExportable() const;

    const char * signerUserID() const;
    const char * signerName() const;
    const char * signerEmail() const;
    const char * signerComment() const;

    unsigned int certClass() const;

    enum Status { NoError = 0, SigExpired, KeyExpired,
		  BadSignature, NoPublicKey, GeneralError };
    Status status() const;
    const char * statusAsString() const;

    const char * policyURL() const;

    unsigned int numNotations() const;
    Notation notation( unsigned int idx ) const;
    std::vector<Notation> notations() const;

  private:
    class Private;
    Private * d;
  };

  //
  //
  // class UserID::Signature::Notation
  //
  //

  class KDE_EXPORT UserID::Signature::Notation {
  public:
    Notation( gpgme_key_t key=0, gpgme_user_id_t uid=0,
	      gpgme_key_sig_t sig=0, gpgme_sig_notation_t nota=0 );
    Notation( gpgme_key_t key, gpgme_user_id_t uid,
	      gpgme_key_sig_t sig, unsigned int idx );
    Notation( const Notation & other );
    ~Notation();

    const Notation & operator=( const Notation & other );

    bool isNull() const;

    Signature parent() const;

    const char * name() const;
    const char * value() const;

  private:
    class Private;
    Private * d;
  };

} // namespace GpgME

#endif // __GPGMEPP_KEY_H__