libzypp  13.10.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/PtrTypes.h"
22 #include "zypp/base/Exception.h"
23 #include "zypp/Pathname.h"
24 #include "zypp/Date.h"
25 
27 namespace zypp
28 {
29 
30  namespace filesystem
31  {
32  class TmpFile;
33  }
34 
39  class BadKeyException : public Exception
40  {
41  public:
46  : Exception( "Bad Key Exception" )
47  {}
48 
49  Pathname keyFile() const
50  { return _keyfile; }
51 
55  BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
56  : Exception( msg_r ), _keyfile(keyfile)
57  {}
59  virtual ~BadKeyException() throw() {};
60  private:
61  Pathname _keyfile;
62  };
64 
75  {
76  public:
78  PublicKeyData();
79 
81 
83  friend class PublicKeyScanner;
84 
86  explicit operator bool() const;
87 
88  public:
90  std::string id() const;
91 
93  std::string name() const;
94 
96  std::string fingerprint() const;
97 
99  Date created() const;
100 
102  Date expires() const;
103 
105  bool expired() const;
106 
112  int daysToLive() const;
113 
126  std::string expiresAsString() const;
127 
129  std::string gpgPubkeyVersion() const;
130 
132  std::string gpgPubkeyRelease() const;
133 
140  std::string asString() const;
141 
142  private:
143  class Impl;
145  };
147 
149  inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
150  { return str << obj.asString(); }
151 
153  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
154 
156  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
157 
159  inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
160  { return !( lhs == rhs ); }
161 
180  {
183 
185  void scan( std::string line_r );
186 
188  std::list<PublicKeyData> _keys;
189 
190  private:
191  class Impl;
193  };
195 
196 
208  class PublicKey
209  {
210  public:
212  class Impl;
213 
214  public:
216  PublicKey();
217 
226  explicit PublicKey( const Pathname & keyFile_r );
227 
234  explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
235 
236  ~PublicKey();
237 
238  public:
240  const PublicKeyData & keyData() const;
241 
242  bool isValid() const
243  { return ! ( id().empty() || fingerprint().empty() ); }
244 
245  std::string id() const;
246  std::string name() const;
247  std::string fingerprint() const;
248  Date created() const;
249  Date expires() const;
250  std::string expiresAsString() const;
251  bool expired() const;
252  int daysToLive() const;
253  std::string gpgPubkeyVersion() const;
254  std::string gpgPubkeyRelease() const;
255  std::string asString() const;
256 
257  public:
259  Pathname path() const;
260 
262  const std::list<PublicKeyData> & hiddenKeys() const;
263 
264  public:
265  bool operator==( const PublicKey & rhs ) const;
266  bool operator==( const std::string & sid ) const;
267 
268  private:
269  friend class KeyRing;
271  PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
272 
273  private:
276  };
278 
280  inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
281  { return str << obj.asString(); }
282 
284  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
285 
287 } // namespace zypp
289 #endif // ZYPP_PUBLICKEY_H
std::string name() const
Key name.
Definition: PublicKey.cc:82
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:91
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:137
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:97
int daysToLive() const
Definition: PublicKey.cc:468
Gpg key handling.
Definition: KeyRing.h:132
std::list< PublicKeyData > _keys
Extracted keys.
Definition: PublicKey.h:188
virtual ~BadKeyException()
Dtor.
Definition: PublicKey.h:59
Class representing one GPG Public Keys data.
Definition: PublicKey.h:74
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:39
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
Definition: PublicKey.cc:447
Date expires() const
Definition: PublicKey.cc:462
std::string asString() const
Definition: PublicKey.cc:480
void scan(std::string line_r)
Feed gpg output line by line into scan.
Definition: PublicKey.cc:289
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
Definition: PublicKey.h:191
bool isValid() const
Definition: PublicKey.h:242
Date created() const
Definition: PublicKey.cc:459
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:134
PublicKeyScanner implementation.
Definition: PublicKey.cc:171
std::string expiresAsString() const
Definition: PublicKey.cc:107
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:69
Pathname keyFile() const
Definition: PublicKey.h:49
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.h:149
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:474
std::string id() const
Definition: PublicKey.cc:450
bool expired() const
Definition: PublicKey.cc:465
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:444
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:275
Store and operate on date (time_t).
Definition: Date.h:31
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:85
std::string expiresAsString() const
Definition: PublicKey.cc:471
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:94
BadKeyException()
Ctor taking message.
Definition: PublicKey.h:45
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:435
Scan abstract from &#39;gpg –with-colons&#39; key listings.
Definition: PublicKey.h:179
PublicKey()
Default ctor.
Definition: PublicKey.cc:422
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:309
PublicKey implementation.
Definition: PublicKey.cc:297
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:208
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Definition: PublicKey.h:280
Base class for Exception.
Definition: Exception.h:143
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:441
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:143
std::string id() const
Key ID.
Definition: PublicKey.cc:79
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:265
PublicKeyData implementation.
Definition: PublicKey.cc:41
std::string fingerprint() const
Definition: PublicKey.cc:456
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
Definition: PublicKey.h:159
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:88
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:477
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:483
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:140
std::string name() const
Definition: PublicKey.cc:453
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:438