1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PublicKey.h
12 #ifndef ZYPP_PUBLICKEY_H
13 #define ZYPP_PUBLICKEY_H
21 #include "zypp/base/PtrTypes.h"
22 #include "zypp/base/Exception.h"
23 #include "zypp/Pathname.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
35 * Exception thrown when the supplied key is
38 class BadKeyException : public Exception
41 /** Ctor taking message.
42 * Use \ref ZYPP_THROW to throw exceptions.
45 : Exception( "Bad Key Exception" )
48 Pathname keyFile() const
51 /** Ctor taking message.
52 * Use \ref ZYPP_THROW to throw exceptions.
54 BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
55 : Exception( msg_r ), _keyfile(keyfile)
58 virtual ~BadKeyException() throw() {};
64 // forward declaration of class Date
67 ///////////////////////////////////////////////////////////////////
69 // CLASS NAME : PublicKey
72 * Class that represent a GPG Public Key.
78 friend std::ostream & operator<<( std::ostream & str, const PublicKey & obj );
88 /** Ctor taking the key from a file.
90 * This is quite expensive, as a copy of the file is created and
91 * used. If you can construct PublicKey from a \ref filesystem::TmpFile,
92 * this prevents copying.
94 * \throws when data does not make a key
97 PublicKey( const Pathname & file );
99 /** Ctor reading the key from a \ref TmpFile.
101 * PublicKey holds a reference on the TmpFile providing the key.
103 * \throws when data does not make a key
106 PublicKey( const filesystem::TmpFile & sharedfile );
111 { return ( ! id().empty() && ! fingerprint().empty() && !path().empty() ); }
113 std::string asString() const;
114 std::string armoredData() const;
115 std::string id() const;
116 std::string name() const;
117 std::string fingerprint() const;
120 * Date when the key was created (time is 00:00:00)
122 Date created() const;
125 * Date when the key expires (time is 00:00:00)
126 * If the key never expires the date is Date() (i.e. 0 seconds since the epoch (1.1.1970))
128 Date expires() const;
130 Pathname path() const;
132 bool operator==( PublicKey b ) const;
133 bool operator==( std::string sid ) const;
136 /** Pointer to implementation */
137 RWCOW_pointer<Impl> _pimpl;
139 ///////////////////////////////////////////////////////////////////
141 /** \relates PublicKey Stream output */
142 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
143 { return str << obj.asString(); }
145 /** \relates PublicKey Detailed stream output */
146 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
148 /////////////////////////////////////////////////////////////////
150 ///////////////////////////////////////////////////////////////////
151 #endif // ZYPP_PUBLICKEY_H