PublicKey.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_PUBLICKEY_H
00013 #define ZYPP_PUBLICKEY_H
00014
00015 #include <iosfwd>
00016 #include <map>
00017 #include <list>
00018 #include <set>
00019 #include <string>
00020
00021 #include "zypp/base/PtrTypes.h"
00022 #include "zypp/base/Exception.h"
00023 #include "zypp/base/SafeBool.h"
00024 #include "zypp/Pathname.h"
00025 #include "zypp/Date.h"
00026
00028 namespace zypp
00029 {
00030
00031 namespace filesystem
00032 {
00033 class TmpFile;
00034 }
00035
00040 class BadKeyException : public Exception
00041 {
00042 public:
00046 BadKeyException()
00047 : Exception( "Bad Key Exception" )
00048 {}
00049
00050 Pathname keyFile() const
00051 { return _keyfile; }
00052
00056 BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
00057 : Exception( msg_r ), _keyfile(keyfile)
00058 {}
00060 virtual ~BadKeyException() throw() {};
00061 private:
00062 Pathname _keyfile;
00063 };
00065
00075 class PublicKeyData : private base::SafeBool<PublicKeyData>
00076 {
00077 public:
00079 PublicKeyData();
00080
00081 ~PublicKeyData();
00082
00084 friend class PublicKeyScanner;
00085
00086 #ifndef SWIG // Swig treats it as syntax error
00087
00088 using base::SafeBool<PublicKeyData>::operator bool_type;
00089 #endif
00090
00091 public:
00093 std::string id() const;
00094
00096 std::string name() const;
00097
00099 std::string fingerprint() const;
00100
00102 Date created() const;
00103
00105 Date expires() const;
00106
00108 bool expired() const;
00109
00115 int daysToLive() const;
00116
00129 std::string expiresAsString() const;
00130
00132 std::string gpgPubkeyVersion() const;
00133
00135 std::string gpgPubkeyRelease() const;
00136
00143 std::string asString() const;
00144
00145 private:
00146 #ifndef SWIG // Swig treats it as syntax error
00147 friend base::SafeBool<PublicKeyData>::operator bool_type() const;
00148 #endif
00149 bool boolTest() const;
00150
00151 private:
00152 class Impl;
00153 RWCOW_pointer<Impl> _pimpl;
00154 };
00156
00158 inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
00159 { return str << obj.asString(); }
00160
00162 std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
00163
00165 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
00166
00168 inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
00169 { return !( lhs == rhs ); }
00170
00188 struct PublicKeyScanner
00189 {
00190 PublicKeyScanner();
00191 ~PublicKeyScanner();
00192
00194 void scan( std::string line_r );
00195
00197 std::list<PublicKeyData> _keys;
00198
00199 private:
00200 class Impl;
00201 RW_pointer<Impl, rw_pointer::Scoped<Impl> > _pimpl;
00202 };
00204
00205
00217 class PublicKey
00218 {
00219 public:
00221 class Impl;
00222
00223 public:
00225 PublicKey();
00226
00235 explicit PublicKey( const Pathname & keyFile_r );
00236
00243 explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
00244
00245 ~PublicKey();
00246
00247 public:
00249 const PublicKeyData & keyData() const;
00250
00251 bool isValid() const
00252 { return ! ( id().empty() || fingerprint().empty() ); }
00253
00254 std::string id() const;
00255 std::string name() const;
00256 std::string fingerprint() const;
00257 Date created() const;
00258 Date expires() const;
00259 std::string expiresAsString() const;
00260 bool expired() const;
00261 int daysToLive() const;
00262 std::string gpgPubkeyVersion() const;
00263 std::string gpgPubkeyRelease() const;
00264 std::string asString() const;
00265
00266 public:
00268 Pathname path() const;
00269
00271 const std::list<PublicKeyData> & hiddenKeys() const;
00272
00273 public:
00274 bool operator==( PublicKey rhs ) const;
00275 bool operator==( std::string sid ) const;
00276
00277 private:
00278 friend class KeyRing;
00280 PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
00281
00282 private:
00284 RWCOW_pointer<Impl> _pimpl;
00285 };
00287
00289 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
00290 { return str << obj.asString(); }
00291
00293 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
00294
00296 }
00298 #endif // ZYPP_PUBLICKEY_H