libzypp  17.34.1
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 #include <utility>
21 
22 #include <zypp/base/Iterable.h>
23 #include <zypp/base/PtrTypes.h>
24 #include <zypp/base/Exception.h>
26 #include <zypp/Pathname.h>
27 #include <zypp/Edition.h>
28 #include <zypp/Date.h>
29 
30 struct _gpgme_key;
31 struct _gpgme_subkey;
32 struct _gpgme_key_sig;
33 
35 namespace zypp
36 {
37 
38  namespace filesystem
39  {
40  class TmpFile;
41  }
42  class PublicKeyData;
43  class KeyManagerCtx;
44 
50  {
51  public:
56  : Exception( "Bad Key Exception" )
57  {}
58 
59  Pathname keyFile() const
60  { return _keyfile; }
61 
65  BadKeyException( const std::string & msg_r, Pathname keyfile = Pathname() )
66  : Exception( msg_r ), _keyfile(std::move(keyfile))
67  {}
69  ~BadKeyException() throw() override {};
70  private:
71  Pathname _keyfile;
72  };
74 
81  {
82  public:
85 
87 
89  explicit operator bool() const;
90 
91  public:
93  std::string id() const;
94 
96  Date created() const;
97 
99  Date expires() const;
100 
102  bool expired() const;
103 
109  int daysToLive() const;
110 
117  std::string asString() const;
118 
119  private:
120  struct Impl;
122  friend class PublicKeyData;
123  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
124  PublicSubkeyData(const _gpgme_subkey *rawSubKeyData);
125  };
127 
129  inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
130  { return str << obj.asString(); }
131 
138  {
139  public:
142 
144 
146  explicit operator bool() const;
147 
148  public:
150  std::string id() const;
151 
153  std::string name() const;
154 
156  Date created() const;
157 
159  Date expires() const;
160 
162  bool expired() const;
163 
169  int daysToLive() const;
170 
172  bool inTrustedRing() const;
173 
175  bool inKnownRing() const;
176 
183  std::string asString() const;
184 
185  private:
186  struct Impl;
188  friend class PublicKeyData;
189  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
190  PublicKeySignatureData(const _gpgme_key_sig *rawKeySignatureData);
191  };
193 
195  inline std::ostream & operator<<( std::ostream & str, const PublicKeySignatureData & obj )
196  { return str << obj.asString(); }
197 
208  {
209  public:
211  PublicKeyData();
212 
213  ~PublicKeyData();
214 
215  PublicKeyData(const PublicKeyData &) = default;
216  PublicKeyData(PublicKeyData &&) noexcept = default;
217  PublicKeyData &operator=(const PublicKeyData &) = default;
218  PublicKeyData &operator=(PublicKeyData &&) noexcept = default;
219 
221  explicit operator bool() const;
222 
223  public:
225  std::string id() const;
226 
228  std::string name() const;
229 
231  std::string fingerprint() const;
232 
234  std::string algoName() const;
235 
237  Date created() const;
238 
240  Date expires() const;
241 
243  bool expired() const;
244 
250  int daysToLive() const;
251 
264  std::string expiresAsString() const;
265 
267  std::string gpgPubkeyVersion() const;
268 
270  std::string gpgPubkeyRelease() const;
271 
273  std::string rpmName () const;
274 
277  { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
278 
285  std::string asString() const;
286 
287  public:
290 
292  bool hasSubkeys() const;
293 
295  Iterable<SubkeyIterator> subkeys() const;
296 
298  Iterable<KeySignatureIterator> signatures() const;
299 
303  bool providesKey( const std::string & id_r ) const;
304 
308  static bool isSafeKeyId( const std::string & id_r )
309  { return id_r.size() >= 16; }
310 
311  public:
313  bool hasSignatures() const;
314 
315  public:
318 
325  AsciiArt asciiArt() const;
326 
327  private:
328  struct Impl;
330 
331  friend class KeyManagerCtx;
332  static PublicKeyData fromGpgmeKey(_gpgme_key *data);
333 
334  PublicKeyData(shared_ptr<Impl> data);
335  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
336  };
338 
340  inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
341  { return str << obj.asString(); }
342 
344  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj ) ZYPP_API;
345 
347  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs ) ZYPP_API;
348 
350  inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
351  { return !( lhs == rhs ); }
352 
365  {
366  public:
368  struct Impl;
369 
370  public:
372  PublicKey();
373 
382  explicit PublicKey( const Pathname & keyFile_r );
383 
390  explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
391 
392  ~PublicKey();
393 
395  static PublicKey noThrow( const Pathname & keyFile_r );
396 
397  public:
399  const PublicKeyData & keyData() const;
400 
402 
403  bool isValid() const
404  { return ! ( id().empty() || fingerprint().empty() ); }
405 
406  std::string id() const;
407  std::string name() const;
408  std::string fingerprint() const;
409  std::string algoName() const;
410  Date created() const;
411  Date expires() const;
412  std::string expiresAsString() const;
413  bool expired() const;
414  int daysToLive() const;
415  std::string gpgPubkeyVersion() const;
416  std::string gpgPubkeyRelease() const;
417  std::string asString() const;
418  std::string rpmName () const;
419 
421  { return keyData().gpgPubkeyEdition(); }
422 
423  bool hasSubkeys() const
424  { return keyData().hasSubkeys(); }
425 
427  { return keyData().subkeys(); }
428 
429  bool providesKey( const std::string & id_r ) const
430  { return keyData().providesKey( id_r ); }
431 
432  static bool isSafeKeyId( const std::string & id_r )
433  { return PublicKeyData::isSafeKeyId(id_r); }
434 
435  public:
437 
439  { return keyData().asciiArt(); }
440 
441  public:
443  Pathname path() const;
444 
446  const std::list<PublicKeyData> & hiddenKeys() const;
447 
451  bool fileProvidesKey( const std::string & id_r ) const;
452 
453  public:
454  bool operator==( const PublicKey & rhs ) const;
455  bool operator!=( const PublicKey & rhs ) const
456  { return not operator==( rhs ); }
457  bool operator==( const std::string & sid ) const;
458  bool operator!=( const std::string & sid ) const
459  { return not operator==( sid ); }
460 
461  private:
462  friend class KeyRing;
464  PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
466  explicit PublicKey( const PublicKeyData & keyData_r );
467 
468  private:
471  };
473 
475  inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
476  { return str << obj.asString(); }
477 
479  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj ) ZYPP_API;
480 
482 } // namespace zypp
484 #endif // ZYPP_PUBLICKEY_H
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:196
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition: PublicKey.h:308
Gpg key handling.
Definition: KeyRing.h:186
bool operator!=(const std::string &sid) const
Definition: PublicKey.h:458
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:120
PublicSubkeyData implementation.
Definition: PublicKey.cc:132
Edition gpgPubkeyEdition() const
!<
Definition: PublicKey.h:420
Class representing one GPG Public Keys data.
Definition: PublicKey.h:207
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:454
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:49
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition: PublicKey.h:317
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:426
String related utilities and Regular expression matching.
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:186
Definition: Arch.h:363
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:275
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
bool hasSubkeys() const
!<
Definition: PublicKey.h:423
std::ostream & operator<<(std::ostream &str, const PublicKeySignatureData &obj)
Definition: PublicKey.h:195
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:469
PublicKeySignatureData implementation.
Definition: PublicKey.cc:206
AsciiArt asciiArt() const
!<
Definition: PublicKey.h:438
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.h:340
bool operator!=(const PublicKey &rhs) const
Definition: PublicKey.h:455
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:288
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:470
Store and operate on date (time_t).
Definition: Date.h:32
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:429
BadKeyException()
Ctor taking message.
Definition: PublicKey.h:55
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
Pathname keyFile() const
Definition: PublicKey.h:59
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Definition: PublicKey.h:129
PublicKey implementation.
Definition: PublicKey.cc:512
~BadKeyException() override
Dtor.
Definition: PublicKey.h:69
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:80
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:364
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Definition: PublicKey.h:475
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition: PublicKey.cc:486
Base class for Exception.
Definition: Exception.h:146
static bool isSafeKeyId(const std::string &id_r)
!<
Definition: PublicKey.h:432
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition: PublicKey.h:276
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:328
BadKeyException(const std::string &msg_r, Pathname keyfile=Pathname())
Ctor taking message.
Definition: PublicKey.h:65
std::string asString() const
Definition: PublicKey.cc:696
PublicKeyData implementation.
Definition: PublicKey.cc:301
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
Definition: PublicKey.h:350
bool isValid() const
Definition: PublicKey.h:403
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
bool providesKey(const std::string &id_r) const
Whether id_r is the id or fingerprint of the primary key or of a subkey.
Definition: PublicKey.cc:475
Class representing a signature on a GPG Public Key.
Definition: PublicKey.h:137
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:466
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Definition: DrunkenBishop.h:61