Remove obsolete ResStatus bits.
[platform/upstream/libzypp.git] / zypp / PublicKey.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/PublicKey.h
10  *
11 */
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
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29   namespace filesystem
30   {
31     class TmpFile;
32   }
33
34   /**
35    * Exception thrown when the supplied key is
36    * not a valid gpg key
37    */
38   class BadKeyException : public Exception
39   {
40     public:
41       /** Ctor taking message.
42      * Use \ref ZYPP_THROW to throw exceptions.
43        */
44       BadKeyException()
45       : Exception( "Bad Key Exception" )
46       {}
47
48       Pathname keyFile() const
49       { return _keyfile; }
50
51       /** Ctor taking message.
52        * Use \ref ZYPP_THROW to throw exceptions.
53        */
54       BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
55       : Exception( msg_r ), _keyfile(keyfile)
56       {}
57       /** Dtor. */
58       virtual ~BadKeyException() throw() {};
59     private:
60       Pathname _keyfile;
61   };
62
63
64   // forward declaration of class Date
65   class Date;
66
67   ///////////////////////////////////////////////////////////////////
68   //
69   //    CLASS NAME : PublicKey
70   //
71   /**
72    * Class that represent a GPG Public Key.
73    *
74    *
75    */
76   class PublicKey
77   {
78     friend std::ostream & operator<<( std::ostream & str, const PublicKey & obj );
79
80   public:
81     /** Implementation  */
82     class Impl;
83
84   public:
85     /** Default ctor. */
86     PublicKey();
87
88     /** Ctor taking the key from a file.
89      *
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.
93      *
94      * \throws when data does not make a key
95      */
96     explicit
97     PublicKey( const Pathname & file );
98
99     /** Ctor reading the key from a \ref TmpFile.
100      *
101      * PublicKey holds a reference on the TmpFile providing the key.
102      *
103      * \throws when data does not make a key
104      */
105     explicit
106     PublicKey( const filesystem::TmpFile & sharedfile );
107
108     ~PublicKey();
109
110     bool isValid() const
111     { return ( ! id().empty() && ! fingerprint().empty() && !path().empty() ); }
112
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;
118
119     /**
120      * Date when the key was created (time is 00:00:00)
121      */
122     Date created() const;
123
124     /**
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))
127      */
128     Date expires() const;
129
130     Pathname path() const;
131
132     bool operator==( PublicKey b ) const;
133     bool operator==( std::string sid ) const;
134
135   private:
136     /** Pointer to implementation */
137     RWCOW_pointer<Impl> _pimpl;
138   };
139   ///////////////////////////////////////////////////////////////////
140
141   /** \relates PublicKey Stream output */
142   inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
143   { return str << obj.asString(); }
144
145   /** \relates PublicKey Detailed stream output */
146   std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
147
148  /////////////////////////////////////////////////////////////////
149 } // namespace zypp
150 ///////////////////////////////////////////////////////////////////
151 #endif // ZYPP_PUBLICKEY_H