libzypp  17.11.4
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:
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  class 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  Date created() const;
162 
164  Date expires() const;
165 
167  bool expired() const;
168 
174  int daysToLive() const;
175 
188  std::string expiresAsString() const;
189 
191  std::string gpgPubkeyVersion() const;
192 
194  std::string gpgPubkeyRelease() const;
195 
197  std::string rpmName () const;
198 
201  { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
202 
209  std::string asString() const;
210 
211  public:
213 
215  bool hasSubkeys() const;
216 
219 
221  bool providesKey( const std::string & id_r ) const;
222 
223  public:
226 
233  AsciiArt asciiArt() const;
234 
235  private:
236  class Impl;
238 
239  friend class KeyManagerCtx;
240  static PublicKeyData fromGpgmeKey(_gpgme_key *data);
241 
242  PublicKeyData(shared_ptr<Impl> data);
243  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
244  };
246 
248  inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
249  { return str << obj.asString(); }
250 
252  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
253 
255  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
256 
258  inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
259  { return !( lhs == rhs ); }
260 
272  class PublicKey
273  {
274  public:
276  class Impl;
277 
278  public:
280  PublicKey();
281 
290  explicit PublicKey( const Pathname & keyFile_r );
291 
298  explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
299 
300  ~PublicKey();
301 
302  public:
304  const PublicKeyData & keyData() const;
305 
307 
308  bool isValid() const
309  { return ! ( id().empty() || fingerprint().empty() ); }
310 
311  std::string id() const;
312  std::string name() const;
313  std::string fingerprint() const;
314  Date created() const;
315  Date expires() const;
316  std::string expiresAsString() const;
317  bool expired() const;
318  int daysToLive() const;
319  std::string gpgPubkeyVersion() const;
320  std::string gpgPubkeyRelease() const;
321  std::string asString() const;
322  std::string rpmName () const;
323 
325  { return keyData().gpgPubkeyEdition(); }
326 
327  bool hasSubkeys() const
328  { return keyData().hasSubkeys(); }
329 
331  { return keyData().subkeys(); }
332 
333  bool providesKey( const std::string & id_r ) const
334  { return keyData().providesKey( id_r ); }
335 
336  public:
338 
340  { return keyData().asciiArt(); }
341 
342  public:
344  Pathname path() const;
345 
347  const std::list<PublicKeyData> & hiddenKeys() const;
348 
349  public:
350  bool operator==( const PublicKey & rhs ) const;
351  bool operator==( const std::string & sid ) const;
352 
353  private:
354  friend class KeyRing;
356  PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
358  explicit PublicKey( const PublicKeyData & keyData_r );
359 
360  private:
363  };
365 
367  inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
368  { return str << obj.asString(); }
369 
371  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
372 
374 } // namespace zypp
376 #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:515
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:509
std::string name() const
Definition: PublicKey.cc:521
Gpg key handling.
Definition: KeyRing.h:168
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:118
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:319
virtual ~BadKeyException()
Dtor.
Definition: PublicKey.h:67
PublicSubkeyData implementation.
Definition: PublicKey.cc:114
Edition gpgPubkeyEdition() const
!<
Definition: PublicKey.h:324
Class representing one GPG Public Keys data.
Definition: PublicKey.h:139
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:172
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:325
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:47
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:145
std::string id() const
Definition: PublicKey.cc:518
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:330
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:536
bool hasSubkeys() const
!<
Definition: PublicKey.h:327
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:127
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition: PublicKey.cc:337
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:275
AsciiArt asciiArt() const
!<
Definition: PublicKey.h:339
PublicKeyData::AsciiArt AsciiArt
Definition: PublicKey.h:337
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.h:248
std::string expiresAsString() const
Definition: PublicKey.cc:539
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:530
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:554
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:362
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition: PublicKey.cc:322
Store and operate on date (time_t).
Definition: Date.h:32
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:301
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition: PublicKey.h:225
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:542
std::string rpmName() const
Definition: PublicKey.cc:551
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:212
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:333
BadKeyException()
Ctor taking message.
Definition: PublicKey.h:53
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:350
Pathname keyFile() const
Definition: PublicKey.h:57
BadKeyException(const std::string &msg_r, const Pathname &keyfile=Pathname())
Ctor taking message.
Definition: PublicKey.h:63
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Definition: PublicKey.h:127
PublicKey()
Default ctor.
Definition: PublicKey.cc:486
PublicKey implementation.
Definition: PublicKey.cc:372
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:545
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:78
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:272
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Definition: PublicKey.h:367
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:169
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition: PublicKey.cc:347
Date created() const
Definition: PublicKey.cc:527
Base class for Exception.
Definition: Exception.h:145
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:512
std::string id() const
Key ID.
Definition: PublicKey.cc:292
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition: PublicKey.h:200
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:236
std::string fingerprint() const
Definition: PublicKey.cc:524
std::string asString() const
Definition: PublicKey.cc:548
bool expired() const
Definition: PublicKey.cc:533
PublicKeyData implementation.
Definition: PublicKey.cc:188
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:350
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
Definition: PublicKey.h:258
bool isValid() const
Definition: PublicKey.h:308
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:340
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:334
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Definition: DrunkenBishop.h:61
PublicKeyData::SubkeyIterator SubkeyIterator
Definition: PublicKey.h:306