1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/FileChecker.h
12 #ifndef ZYPP_FILECHECKER_H
13 #define ZYPP_FILECHECKER_H
17 #include "zypp/base/Exception.h"
18 #include "zypp/base/Function.h"
19 #include "zypp/PathInfo.h"
20 #include "zypp/CheckSum.h"
21 #include "zypp/KeyContext.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
30 * Functor signature used to check files.
31 * \param file File to check.
33 * \throws FileCheckException when the file does not
34 * validate and the user don't want to continue.
36 typedef function<void ( const Pathname &file )> FileChecker;
38 class FileCheckException : public Exception
41 FileCheckException(const std::string &msg)
46 class CheckSumCheckException : public FileCheckException
51 class SignatureCheckException : public FileCheckException
57 * Built in file checkers
61 * \short Checks for a valid checksum and interacts with the user.
63 class ChecksumFileChecker
68 * \param checksum Checksum that validates the file
70 ChecksumFileChecker( const CheckSum &checksum );
72 * \short Try to validate the file
73 * \param file File to validate.
75 * \throws CheckSumCheckException if validation fails
77 void operator()( const Pathname &file ) const;
83 * \short Checks for the validity of a signature
85 class SignatureFileChecker
90 * \param signature Signature that validates the file
92 SignatureFileChecker( const Pathname &signature );
95 * Default Constructor.
96 * \short Signature for unsigned files
97 * Use it when you dont have a signature but you want
98 * to check the user to accept an unsigned file.
100 SignatureFileChecker();
103 * Set context for this checker.
105 * Use this method if you're not adding the key (with context) via
106 * one of the addPublicKey methods. The addPublicKey method overwrites
109 void setKeyContext(const KeyContext & keycontext);
112 * add a public key to the list of known keys
114 void addPublicKey( const PublicKey & publickey, const KeyContext & keycontext = KeyContext());
115 /** \overload Convenience taking the public keys pathname. */
116 void addPublicKey( const Pathname & publickey, const KeyContext & keycontext = KeyContext());
119 * \short Try to validate the file
120 * \param file File to validate.
122 * \throws SignatureCheckException if validation fails
124 void operator()( const Pathname &file ) const;
132 * \short Checks for nothing
133 * Used as the default checker
135 class NullFileChecker
138 void operator()( const Pathname &file ) const;
142 * \short Checker composed of more checkers.
144 * Allows to create a checker composed of various
145 * checkers altothether. It will only
146 * validate if all the checkers validate.
149 * CompositeFileChecker com;
152 * fetcher.enqueue(location, com);
155 class CompositeFileChecker
158 void add( const FileChecker &checker );
160 * \throws FileCheckException if validation fails
162 void operator()( const Pathname &file ) const;
164 int checkersSize() const { return _checkers.size(); }
166 std::list<FileChecker> _checkers;
169 /** \relates FileChecker Stream output */
170 std::ostream & operator<<( std::ostream & str, const FileChecker & obj );
172 /////////////////////////////////////////////////////////////////
174 ///////////////////////////////////////////////////////////////////
175 #endif // ZYPP_FILECHECKER_H