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:
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
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:187
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:184
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
Definition: PublicKey.cc:521
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:515
std::string name() const
Definition: PublicKey.cc:527
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:333
virtual ~BadKeyException()
Dtor.
Definition: PublicKey.h:67
PublicSubkeyData implementation.
Definition: PublicKey.cc:123
Edition gpgPubkeyEdition() const
!<
Definition: PublicKey.h:328
Class representing one GPG Public Keys data.
Definition: PublicKey.h:139
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:181
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:339
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:47
std::string algoName() const
Key algorithm string like RSA 2048
Definition: PublicKey.cc:312
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:154
std::string id() const
Definition: PublicKey.cc:524
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:334
std::string name() const
Key name.
Definition: PublicKey.cc:306
String related utilities and Regular expression matching.
Date created() const
Creation date.
Definition: PublicKey.cc:175
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
int daysToLive() const
Definition: PublicKey.cc:545
bool hasSubkeys() const
!<
Definition: PublicKey.h:331
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:351
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:286
AsciiArt asciiArt() const
!<
Definition: PublicKey.h:343
PublicKeyData::AsciiArt AsciiArt
Definition: PublicKey.h:341
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.h:251
std::string expiresAsString() const
Definition: PublicKey.cc:548
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:330
std::string id() const
Subkey ID.
Definition: PublicKey.cc:172
Date expires() const
Definition: PublicKey.cc:539
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:563
std::string expiresAsString() const
Definition: PublicKey.cc:327
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:324
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:366
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition: PublicKey.cc:336
Store and operate on date (time_t).
Definition: Date.h:32
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:315
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition: PublicKey.h:228
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:551
std::string rpmName() const
Definition: PublicKey.cc:560
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:215
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:337
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:364
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:492
PublicKey implementation.
Definition: PublicKey.cc:387
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:309
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:321
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:554
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:275
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Definition: PublicKey.h:371
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:178
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition: PublicKey.cc:361
Date created() const
Definition: PublicKey.cc:536
Base class for Exception.
Definition: Exception.h:145
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:518
std::string id() const
Key ID.
Definition: PublicKey.cc:303
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition: PublicKey.h:203
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:239
std::string fingerprint() const
Definition: PublicKey.cc:530
std::string asString() const
Definition: PublicKey.cc:557
bool expired() const
Definition: PublicKey.cc:542
PublicKeyData implementation.
Definition: PublicKey.cc:197
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:364
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
Definition: PublicKey.h:261
bool isValid() const
Definition: PublicKey.h:311
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition: PublicKey.cc:297
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:354
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:318
std::string algoName() const
Definition: PublicKey.cc:533
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:348
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:309