libzypp  17.2.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"
24 #include "zypp/Pathname.h"
25 #include "zypp/Edition.h"
26 #include "zypp/Date.h"
27 
28 struct _gpgme_key;
29 struct _gpgme_subkey;
30 
32 namespace zypp
33 {
34 
35  namespace filesystem
36  {
37  class TmpFile;
38  }
39  class PublicKeyData;
40  class KeyManagerCtx;
41 
46  class BadKeyException : public Exception
47  {
48  public:
53  : Exception( "Bad Key Exception" )
54  {}
55 
56  Pathname keyFile() const
57  { return _keyfile; }
58 
62  BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
63  : Exception( msg_r ), _keyfile(keyfile)
64  {}
66  virtual ~BadKeyException() throw() {};
67  private:
69  };
71 
78  {
79  public:
82 
84 
86  explicit operator bool() const;
87 
88  public:
90  std::string id() const;
91 
93  Date created() const;
94 
96  Date expires() const;
97 
99  bool expired() const;
100 
106  int daysToLive() const;
107 
114  std::string asString() const;
115 
116  private:
117  class Impl;
119  friend class PublicKeyData;
120  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
121  PublicSubkeyData(const _gpgme_subkey *rawSubKeyData);
122  };
124 
126  inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
127  { return str << obj.asString(); }
128 
139  {
140  public:
142  PublicKeyData();
143 
144  ~PublicKeyData();
145 
147  explicit operator bool() const;
148 
149  public:
151  std::string id() const;
152 
154  std::string name() const;
155 
157  std::string fingerprint() const;
158 
160  Date created() const;
161 
163  Date expires() const;
164 
166  bool expired() const;
167 
173  int daysToLive() const;
174 
187  std::string expiresAsString() const;
188 
190  std::string gpgPubkeyVersion() const;
191 
193  std::string gpgPubkeyRelease() const;
194 
197  { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
198 
205  std::string asString() const;
206 
207  public:
209 
211  bool hasSubkeys() const;
212 
215 
217  bool providesKey( const std::string & id_r ) const;
218 
219  private:
220  class Impl;
222 
223  friend class KeyManagerCtx;
224  static PublicKeyData fromGpgmeKey(_gpgme_key *data);
225 
226  PublicKeyData(shared_ptr<Impl> data);
227  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
228  };
230 
232  inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
233  { return str << obj.asString(); }
234 
236  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
237 
239  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
240 
242  inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
243  { return !( lhs == rhs ); }
244 
256  class PublicKey
257  {
258  public:
260  class Impl;
261 
262  public:
264  PublicKey();
265 
274  explicit PublicKey( const Pathname & keyFile_r );
275 
282  explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
283 
284  ~PublicKey();
285 
286  public:
288  const PublicKeyData & keyData() const;
289 
291 
292  bool isValid() const
293  { return ! ( id().empty() || fingerprint().empty() ); }
294 
295  std::string id() const;
296  std::string name() const;
297  std::string fingerprint() const;
298  Date created() const;
299  Date expires() const;
300  std::string expiresAsString() const;
301  bool expired() const;
302  int daysToLive() const;
303  std::string gpgPubkeyVersion() const;
304  std::string gpgPubkeyRelease() const;
305  std::string asString() const;
306 
308  { return keyData().gpgPubkeyEdition(); }
309 
310  bool hasSubkeys() const
311  { return keyData().hasSubkeys(); }
312 
314  { return keyData().subkeys(); }
315 
316  bool providesKey( const std::string & id_r ) const
317  { return keyData().providesKey( id_r ); }
318 
319  public:
321  Pathname path() const;
322 
324  const std::list<PublicKeyData> & hiddenKeys() const;
325 
326  public:
327  bool operator==( const PublicKey & rhs ) const;
328  bool operator==( const std::string & sid ) const;
329 
330  private:
331  friend class KeyRing;
333  PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
335  explicit PublicKey( const PublicKeyData & keyData_r );
336 
337  private:
340  };
342 
344  inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
345  { return str << obj.asString(); }
346 
348  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
349 
351 } // namespace zypp
353 #endif // ZYPP_PUBLICKEY_H
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:178
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:175
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
Definition: PublicKey.cc:505
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:499
std::string name() const
Definition: PublicKey.cc:511
Gpg key handling.
Definition: KeyRing.h:135
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:117
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:319
virtual ~BadKeyException()
Dtor.
Definition: PublicKey.h:66
PublicSubkeyData implementation.
Definition: PublicKey.cc:114
Edition gpgPubkeyEdition() const
!<
Definition: PublicKey.h:307
Class representing one GPG Public Keys data.
Definition: PublicKey.h:138
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:172
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:322
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:46
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:145
std::string id() const
Definition: PublicKey.cc:508
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:313
std::string name() const
Key name.
Definition: PublicKey.cc:295
String related utilities and Regular expression matching.
Date created() const
Creation date.
Definition: PublicKey.cc:166
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
int daysToLive() const
Definition: PublicKey.cc:526
bool hasSubkeys() const
!<
Definition: PublicKey.h:310
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:126
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition: PublicKey.cc:334
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:275
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.h:232
std::string expiresAsString() const
Definition: PublicKey.cc:529
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:316
std::string id() const
Subkey ID.
Definition: PublicKey.cc:163
Date expires() const
Definition: PublicKey.cc:520
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:541
std::string expiresAsString() const
Definition: PublicKey.cc:313
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:310
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:339
Store and operate on date (time_t).
Definition: Date.h:32
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:301
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:532
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:208
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:316
BadKeyException()
Ctor taking message.
Definition: PublicKey.h:52
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:340
Pathname keyFile() const
Definition: PublicKey.h:56
BadKeyException(const std::string &msg_r, const Pathname &keyfile=Pathname())
Ctor taking message.
Definition: PublicKey.h:62
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Definition: PublicKey.h:126
PublicKey()
Default ctor.
Definition: PublicKey.cc:476
PublicKey implementation.
Definition: PublicKey.cc:362
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:298
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:307
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:535
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:77
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:256
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Definition: PublicKey.h:344
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:169
Date created() const
Definition: PublicKey.cc:517
Base class for Exception.
Definition: Exception.h:145
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:502
std::string id() const
Key ID.
Definition: PublicKey.cc:292
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition: PublicKey.h:196
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:220
std::string fingerprint() const
Definition: PublicKey.cc:514
std::string asString() const
Definition: PublicKey.cc:538
bool expired() const
Definition: PublicKey.cc:523
PublicKeyData implementation.
Definition: PublicKey.cc:188
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:340
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
Definition: PublicKey.h:242
bool isValid() const
Definition: PublicKey.h:292
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition: PublicKey.cc:286
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool providesKey(const std::string &id_r) const
Whether id_r is the id of the primary key or of a subkey.
Definition: PublicKey.cc:337
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:304
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:331
PublicKeyData::SubkeyIterator SubkeyIterator
Definition: PublicKey.h:290