libzypp  17.14.0
PublicKey.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_PUBLICKEY_H
13 #define ZYPP_PUBLICKEY_H
14 
15 #include <iosfwd>
16 #include <map>
17 #include <list>
18 #include <set>
19 #include <string>
20 
21 #include "zypp/base/Iterable.h"
22 #include "zypp/base/PtrTypes.h"
23 #include "zypp/base/Exception.h"
25 #include "zypp/Pathname.h"
26 #include "zypp/Edition.h"
27 #include "zypp/Date.h"
28 
29 struct _gpgme_key;
30 struct _gpgme_subkey;
31 
33 namespace zypp
34 {
35 
36  namespace filesystem
37  {
38  class TmpFile;
39  }
40  class PublicKeyData;
41  class KeyManagerCtx;
42 
47  class BadKeyException : public Exception
48  {
49  public:
54  : Exception( "Bad Key Exception" )
55  {}
56 
57  Pathname keyFile() const
58  { return _keyfile; }
59 
63  BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
64  : Exception( msg_r ), _keyfile(keyfile)
65  {}
67  virtual ~BadKeyException() throw() {};
68  private:
69  Pathname _keyfile;
70  };
72 
79  {
80  public:
83 
85 
87  explicit operator bool() const;
88 
89  public:
91  std::string id() const;
92 
94  Date created() const;
95 
97  Date expires() const;
98 
100  bool expired() const;
101 
107  int daysToLive() const;
108 
115  std::string asString() const;
116 
117  private:
118  struct Impl;
120  friend class PublicKeyData;
121  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
122  PublicSubkeyData(const _gpgme_subkey *rawSubKeyData);
123  };
125 
127  inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
128  { return str << obj.asString(); }
129 
140  {
141  public:
143  PublicKeyData();
144 
145  ~PublicKeyData();
146 
148  explicit operator bool() const;
149 
150  public:
152  std::string id() const;
153 
155  std::string name() const;
156 
158  std::string fingerprint() const;
159 
161  std::string algoName() const;
162 
164  Date created() const;
165 
167  Date expires() const;
168 
170  bool expired() const;
171 
177  int daysToLive() const;
178 
191  std::string expiresAsString() const;
192 
194  std::string gpgPubkeyVersion() const;
195 
197  std::string gpgPubkeyRelease() const;
198 
200  std::string rpmName () const;
201 
204  { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
205 
212  std::string asString() const;
213 
214  public:
216 
218  bool hasSubkeys() const;
219 
222 
224  bool providesKey( const std::string & id_r ) const;
225 
226  public:
229 
236  AsciiArt asciiArt() const;
237 
238  private:
239  struct Impl;
241 
242  friend class KeyManagerCtx;
243  static PublicKeyData fromGpgmeKey(_gpgme_key *data);
244 
245  PublicKeyData(shared_ptr<Impl> data);
246  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
247  };
249 
251  inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
252  { return str << obj.asString(); }
253 
255  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
256 
258  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
259 
261  inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
262  { return !( lhs == rhs ); }
263 
275  class PublicKey
276  {
277  public:
279  struct Impl;
280 
281  public:
283  PublicKey();
284 
293  explicit PublicKey( const Pathname & keyFile_r );
294 
301  explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
302 
303  ~PublicKey();
304 
305  public:
307  const PublicKeyData & keyData() const;
308 
310 
311  bool isValid() const
312  { return ! ( id().empty() || fingerprint().empty() ); }
313 
314  std::string id() const;
315  std::string name() const;
316  std::string fingerprint() const;
317  std::string algoName() const;
318  Date created() const;
319  Date expires() const;
320  std::string expiresAsString() const;
321  bool expired() const;
322  int daysToLive() const;
323  std::string gpgPubkeyVersion() const;
324  std::string gpgPubkeyRelease() const;
325  std::string asString() const;
326  std::string rpmName () const;
327 
329  { return keyData().gpgPubkeyEdition(); }
330 
331  bool hasSubkeys() const
332  { return keyData().hasSubkeys(); }
333 
335  { return keyData().subkeys(); }
336 
337  bool providesKey( const std::string & id_r ) const
338  { return keyData().providesKey( id_r ); }
339 
340  public:
342 
344  { return keyData().asciiArt(); }
345 
346  public:
348  Pathname path() const;
349 
351  const std::list<PublicKeyData> & hiddenKeys() const;
352 
353  public:
354  bool operator==( const PublicKey & rhs ) const;
355  bool operator==( const std::string & sid ) const;
356 
357  private:
358  friend class KeyRing;
360  PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
362  explicit PublicKey( const PublicKeyData & keyData_r );
363 
364  private:
367  };
369 
371  inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
372  { return str << obj.asString(); }
373 
375  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
376 
378 } // namespace zypp
380 #endif // ZYPP_PUBLICKEY_H