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