libzypp  11.13.5
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==( PublicKey rhs ) const; // FIXME: change arg to const&
266  bool operator==( std::string sid ) const; // FIXME: change arg to 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