ignore
[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   
30   class BadKeyException : public Exception
31   {
32     public:
33       /** Ctor taking message.
34      * Use \ref ZYPP_THROW to throw exceptions.
35        */
36       BadKeyException()
37       : Exception( "Bad Key Exception" )
38       {}
39       
40       Pathname keyFile() const
41       { return _keyfile; }
42       
43       /** Ctor taking message.
44        * Use \ref ZYPP_THROW to throw exceptions.
45        */
46       BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
47       : Exception( msg_r ), _keyfile(keyfile)
48       {}
49       /** Dtor. */
50       virtual ~BadKeyException() throw() {};
51     private:
52       Pathname _keyfile;
53   };
54   
55   
56   ///////////////////////////////////////////////////////////////////
57   //
58   //    CLASS NAME : PublicKey
59   //
60   /** Class that represent a GPG Public Key
61   */
62   class PublicKey
63   {
64     friend std::ostream & operator<<( std::ostream & str, const PublicKey & obj );
65
66   public:
67     /** Implementation  */
68     class Impl;
69
70   public:
71     PublicKey();
72    /** Ctor 
73     * \throws when data does not make a key
74     */
75     PublicKey(const Pathname &file);
76     
77     ~PublicKey();
78    
79     bool isValid() const
80     { return ( ! id().empty() && ! fingerprint().empty() && !path().empty() ); }
81     
82     std::string asString() const;
83     std::string armoredData() const;
84     std::string id() const;
85     std::string name() const;
86     std::string fingerprint() const;
87     Pathname path() const; 
88     
89     bool operator==( PublicKey b )
90     { return (b.id() == id()) && (b.fingerprint() == fingerprint() ); }
91     
92     bool operator==( std::string sid )
93     { return sid == id(); }
94     
95   private:
96     /** Pointer to implementation */
97     RWCOW_pointer<Impl> _pimpl;
98   };
99   ///////////////////////////////////////////////////////////////////
100
101   /** \relates PublicKey Stream output */
102   inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
103   { return str << obj.asString(); }
104
105   /////////////////////////////////////////////////////////////////
106 } // namespace zypp
107 ///////////////////////////////////////////////////////////////////
108 #endif // ZYPP_PUBLICKEY_H