ignore
[platform/upstream/libzypp.git] / zypp / KeyRing.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/KeyRing.h
10  *
11 */
12 #ifndef ZYPP_KEYRING_H
13 #define ZYPP_KEYRING_H
14
15 #include <iosfwd>
16 #include <map>
17 #include <list>
18 #include <set>
19 #include <string>
20
21 #include "zypp/base/ReferenceCounted.h"
22 #include "zypp/Callback.h"
23 #include "zypp/base/PtrTypes.h"
24 #include "zypp/Locale.h"
25 #include "zypp/PublicKey.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31   DEFINE_PTR_TYPE(KeyRing);
32
33   struct KeyRingReport : public callback::ReportBase
34   {
35     virtual bool askUserToAcceptUnsignedFile( const std::string &file );
36     virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id );
37     virtual bool askUserToTrustKey( const PublicKey &key);
38     virtual bool askUserToImportKey( const PublicKey &key);
39     virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key );
40   };
41   
42   struct KeyRingSignals : public callback::ReportBase
43   {
44     virtual void trustedKeyAdded( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
45     {}
46     virtual void trustedKeyRemoved( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
47     {}
48   };
49
50   class KeyRingException : public Exception
51    {
52      public:
53        /** Ctor taking message.
54       * Use \ref ZYPP_THROW to throw exceptions.
55         */
56        KeyRingException()
57        : Exception( "Bad Key Exception" )
58        {}
59        /** Ctor taking message.
60         * Use \ref ZYPP_THROW to throw exceptions.
61         */
62        KeyRingException( const std::string & msg_r )
63        : Exception( msg_r )
64        {}
65        /** Dtor. */
66        virtual ~KeyRingException() throw() {};
67    };
68   
69   ///////////////////////////////////////////////////////////////////
70   //
71   //    CLASS NAME : KeyRing
72   //
73   /** Class that represent a text and multiple translations.
74   */
75   class KeyRing  : public base::ReferenceCounted, private base::NonCopyable
76   {
77     friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
78
79   public:
80     /** Implementation  */
81     class Impl;
82
83   public:
84     /** Default ctor */
85     KeyRing(const Pathname &baseTmpDir);
86     //explicit
87     //KeyRing(const Pathname &general_kr, const Pathname &trusted_kr);
88
89     /**
90      * imports a key from a file.
91      * throw if key was not imported
92      */
93     void importKey( const PublicKey &key, bool trusted = false);
94     
95     void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
96     { dumpPublicKey(id, true, stream); }
97     
98     void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
99     { dumpPublicKey(id, false, stream); }
100     
101     void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
102     
103     /**
104      * reads the public key id from a signature
105      */
106     std::string readSignatureKeyId( const Pathname &signature );
107     
108     /**
109      * removes a key from the keyring.
110      * If trusted is true, Remove it from trusted keyring too.
111      */
112     void deleteKey( const std::string &id, bool trusted =  false);
113
114     std::list<PublicKey> publicKeys();
115     std::list<PublicKey> trustedPublicKeys();
116
117     /**
118      * Follows a signature verification interacting with the user.
119      * The boolr eturned depends on user desicion to trust or not.
120      */
121     bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature);
122     bool verifyFileSignature( const Pathname &file, const Pathname &signature);
123     bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
124
125 /** Dtor */
126     ~KeyRing();
127
128   public:
129
130     /** Synonym for \ref text */
131     //std::string asString() const
132     //{}
133
134   private:
135     /** Pointer to implementation */
136     RWCOW_pointer<Impl> _pimpl;
137   };
138   ///////////////////////////////////////////////////////////////////
139
140   /** \relates KeyRing Stream output */
141   inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ )
142   {
143     //return str << obj.asString();
144     return str;
145   }
146
147   /////////////////////////////////////////////////////////////////
148 } // namespace zypp
149 ///////////////////////////////////////////////////////////////////
150 #endif // ZYPP_KEYRING_H