1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/KeyRing.h
12 #ifndef ZYPP_KEYRING_H
13 #define ZYPP_KEYRING_H
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"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 DEFINE_PTR_TYPE(KeyRing);
33 struct KeyRingReport : public callback::ReportBase
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 );
42 struct KeyRingSignals : public callback::ReportBase
44 virtual void trustedKeyAdded( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
46 virtual void trustedKeyRemoved( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
50 class KeyRingException : public Exception
53 /** Ctor taking message.
54 * Use \ref ZYPP_THROW to throw exceptions.
57 : Exception( "Bad Key Exception" )
59 /** Ctor taking message.
60 * Use \ref ZYPP_THROW to throw exceptions.
62 KeyRingException( const std::string & msg_r )
66 virtual ~KeyRingException() throw() {};
69 ///////////////////////////////////////////////////////////////////
71 // CLASS NAME : KeyRing
73 /** Class that represent a text and multiple translations.
75 class KeyRing : public base::ReferenceCounted, private base::NonCopyable
77 friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
85 KeyRing(const Pathname &baseTmpDir);
87 //KeyRing(const Pathname &general_kr, const Pathname &trusted_kr);
90 * imports a key from a file.
91 * throw if key was not imported
93 void importKey( const PublicKey &key, bool trusted = false);
95 void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
96 { dumpPublicKey(id, true, stream); }
98 void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
99 { dumpPublicKey(id, false, stream); }
101 void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
104 * reads the public key id from a signature
106 std::string readSignatureKeyId( const Pathname &signature );
109 * removes a key from the keyring.
110 * If trusted is true, Remove it from trusted keyring too.
112 void deleteKey( const std::string &id, bool trusted = false);
114 std::list<PublicKey> publicKeys();
115 std::list<PublicKey> trustedPublicKeys();
118 * Follows a signature verification interacting with the user.
119 * The boolr eturned depends on user desicion to trust or not.
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);
130 /** Synonym for \ref text */
131 //std::string asString() const
135 /** Pointer to implementation */
136 RWCOW_pointer<Impl> _pimpl;
138 ///////////////////////////////////////////////////////////////////
140 /** \relates KeyRing Stream output */
141 inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ )
143 //return str << obj.asString();
147 /////////////////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////////////////
150 #endif // ZYPP_KEYRING_H