implement signature file to id, keyexists, and others
[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
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29
30   DEFINE_PTR_TYPE(KeyRing);
31
32   struct KeyRingReport : public callback::ReportBase
33   {
34     virtual bool askUserToTrustKey( const std::string keyid, const std::string keyname )
35     { return true; }
36     
37   };
38   
39   struct KeyRingSignals : public callback::ReportBase
40   {
41     virtual void trustedKeyAdded( const KeyRing &keyring, const std::string keyid, const std::string keyname )
42     {}
43     virtual void trustedKeyRemoved( const KeyRing &keyring, const std::string keyid, const std::string keyname )
44     {}
45   };
46   
47   struct PublicKey
48   {
49     std::string id;
50     std::string name;
51     std::string fingerprint;
52   };
53
54   ///////////////////////////////////////////////////////////////////
55   //
56   //    CLASS NAME : KeyRing
57   //
58   /** Class that represent a text and multiple translations.
59   */
60   class KeyRing  : public base::ReferenceCounted, private base::NonCopyable
61   {
62     friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
63
64   public:
65     /** Implementation  */
66     class Impl;
67
68   public:
69     /** Default ctor */
70     KeyRing();
71     /** Ctor \todo Make ctor it explicit */
72     explicit
73     KeyRing(const Pathname &general_kr, const Pathname &trusted_kr);
74
75     /**
76      * imports a key from a file.
77      * throw if key was not imported
78      */
79     void importKey( const Pathname &keyfile, bool trusted = false);
80     PublicKey readPublicKey( const Pathname &keyfile );
81     std::string readSignatureKeyId( const Pathname &keyfile );
82     
83     /**
84      * removes a key from the keyring.
85      * If trusted is true, Remove it from trusted keyring too.
86      */
87     void deleteKey( const std::string &id, bool trusted =  false);
88
89     std::list<PublicKey> publicKeys();
90     std::list<PublicKey> trustedPublicKeys();
91
92     /**
93      * Follows a signature verification interacting with the user.
94      * The boolr eturned depends on user desicion to trust or not.
95      */
96     bool verifyFileSignatureWorkflow( const Pathname &file, const Pathname &signature);
97     
98     bool verifyFileSignature( const Pathname &file, const Pathname &signature);
99     bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
100
101 /** Dtor */
102     ~KeyRing();
103
104   public:
105
106     /** Synonym for \ref text */
107     //std::string asString() const
108     //{}
109
110   private:
111     /** Pointer to implementation */
112     RWCOW_pointer<Impl> _pimpl;
113   };
114   ///////////////////////////////////////////////////////////////////
115
116   /** \relates KeyRing Stream output */
117   inline std::ostream & operator<<( std::ostream & str, const KeyRing & obj )
118   {
119     //return str << obj.asString();
120     return str;
121   }
122
123   /////////////////////////////////////////////////////////////////
124 } // namespace zypp
125 ///////////////////////////////////////////////////////////////////
126 #endif // ZYPP_KEYRING_H