libzypp  15.28.6
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/Date.h"
26 
28 namespace zypp
29 {
30 
31  namespace filesystem
32  {
33  class TmpFile;
34  }
35  class PublicKeyData;
36 
41  class BadKeyException : public Exception
42  {
43  public:
48  : Exception( "Bad Key Exception" )
49  {}
50 
51  Pathname keyFile() const
52  { return _keyfile; }
53 
57  BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
58  : Exception( msg_r ), _keyfile(keyfile)
59  {}
61  virtual ~BadKeyException() throw() {};
62  private:
63  Pathname _keyfile;
64  };
66 
73  {
74  public:
77 
79 
81  explicit operator bool() const;
82 
83  public:
85  std::string id() const;
86 
88  Date created() const;
89 
91  Date expires() const;
92 
94  bool expired() const;
95 
101  int daysToLive() const;
102 
109  std::string asString() const;
110 
111  private:
112  class Impl;
114  friend class PublicKeyScanner;
115  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
116  };
118 
120  inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
121  { return str << obj.asString(); }
122 
133  {
134  public:
136  PublicKeyData();
137 
138  ~PublicKeyData();
139 
141  explicit operator bool() const;
142 
143  public:
145  std::string id() const;
146 
148  std::string name() const;
149 
151  std::string fingerprint() const;
152 
154  Date created() const;
155 
157  Date expires() const;
158 
160  bool expired() const;
161 
167  int daysToLive() const;
168 
181  std::string expiresAsString() const;
182 
184  std::string gpgPubkeyVersion() const;
185 
187  std::string gpgPubkeyRelease() const;
188 
195  std::string asString() const;
196 
197  public:
199 
201  bool hasSubkeys() const;
202 
205 
207  bool providesKey( const std::string & id_r ) const;
208 
209  private:
210  class Impl;
212  friend class PublicKeyScanner;
213  friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
214  };
216 
218  inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
219  { return str << obj.asString(); }
220 
222  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
223 
225  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
226 
228  inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
229  { return !( lhs == rhs ); }
230 
249  {
252 
254  void scan( std::string line_r );
255 
257  std::list<PublicKeyData> _keys;
258 
259  private:
260  class Impl;
262  };
264 
265 
277  class PublicKey
278  {
279  public:
281  class Impl;
282 
283  public:
285  PublicKey();
286 
295  explicit PublicKey( const Pathname & keyFile_r );
296 
303  explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
304 
305  ~PublicKey();
306 
307  public:
309  const PublicKeyData & keyData() const;
310 
312 
313  bool isValid() const
314  { return ! ( id().empty() || fingerprint().empty() ); }
315 
316  std::string id() const;
317  std::string name() const;
318  std::string fingerprint() const;
319  Date created() const;
320  Date expires() const;
321  std::string expiresAsString() const;
322  bool expired() const;
323  int daysToLive() const;
324  std::string gpgPubkeyVersion() const;
325  std::string gpgPubkeyRelease() const;
326  std::string asString() const;
327 
328  bool hasSubkeys() const
329  { return keyData().hasSubkeys(); }
330 
332  { return keyData().subkeys(); }
333 
334  bool providesKey( const std::string & id_r ) const
335  { return keyData().providesKey( id_r ); }
336 
337  public:
339  Pathname path() const;
340 
342  const std::list<PublicKeyData> & hiddenKeys() const;
343 
344  public:
345  bool operator==( const PublicKey & rhs ) const;
346  bool operator==( const std::string & sid ) const;
347 
348  private:
349  friend class KeyRing;
351  PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
352 
353  private:
356  };
358 
360  inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
361  { return str << obj.asString(); }
362 
364  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
365 
367 } // namespace zypp
369 #endif // ZYPP_PUBLICKEY_H
std::string name() const
Key name.
Definition: PublicKey.cc:225
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:234
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:249
Date created() const
Creation date.
Definition: PublicKey.cc:147
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:240
int daysToLive() const
Definition: PublicKey.cc:606
Gpg key handling.
Definition: KeyRing.h:135
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:112
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:331
std::list< PublicKeyData > _keys
Extracted keys.
Definition: PublicKey.h:257
virtual ~BadKeyException()
Dtor.
Definition: PublicKey.h:61
PublicSubkeyData implementation.
Definition: PublicKey.cc:109
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition: PublicKey.cc:264
bool hasSubkeys() const
!<
Definition: PublicKey.h:328
Class representing one GPG Public Keys data.
Definition: PublicKey.h:132
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:41
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:261
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:134
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
Definition: PublicKey.cc:585
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:150
Date expires() const
Definition: PublicKey.cc:600
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:267
std::string asString() const
Definition: PublicKey.cc:618
void scan(std::string line_r)
Feed gpg output line by line into scan.
Definition: PublicKey.cc:419
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
Definition: PublicKey.h:260
bool isValid() const
Definition: PublicKey.h:313
Date created() const
Definition: PublicKey.cc:597
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:246
PublicKeyScanner implementation.
Definition: PublicKey.cc:292
std::string expiresAsString() const
Definition: PublicKey.cc:243
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
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:212
Pathname keyFile() const
Definition: PublicKey.h:51
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.h:218
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:612
std::string id() const
Definition: PublicKey.cc:588
bool expired() const
Definition: PublicKey.cc:603
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:582
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:355
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:334
Store and operate on date (time_t).
Definition: Date.h:32
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:228
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:198
std::string expiresAsString() const
Definition: PublicKey.cc:609
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:237
BadKeyException()
Ctor taking message.
Definition: PublicKey.h:47
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:446
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:270
BadKeyException(const std::string &msg_r, const Pathname &keyfile=Pathname())
Ctor taking message.
Definition: PublicKey.h:57
Scan abstract from 'gpg –with-colons' key listings.
Definition: PublicKey.h:248
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Definition: PublicKey.h:120
PublicKey()
Default ctor.
Definition: PublicKey.cc:560
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:159
PublicKey implementation.
Definition: PublicKey.cc:427
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:156
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:72
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:277
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Definition: PublicKey.h:360
Base class for Exception.
Definition: Exception.h:143
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:579
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:210
std::string id() const
Key ID.
Definition: PublicKey.cc:222
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:153
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:285
PublicKeyData implementation.
Definition: PublicKey.cc:168
std::string fingerprint() const
Definition: PublicKey.cc:594
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:270
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
Definition: PublicKey.h:228
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:231
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:615
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:621
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:252
std::string name() const
Definition: PublicKey.cc:591
std::string id() const
Subkey ID.
Definition: PublicKey.cc:144
PublicKeyData::SubkeyIterator SubkeyIterator
Definition: PublicKey.h:311