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 { /////////////////////////////////////////////////////////////////
28 * Functor signature used to check files.
29 * \param file File to check.
31 * \throws FileCheckException when the file does not
32 * validate and the user don't want to continue.
34 typedef function<void ( const Pathname &file )> FileChecker;
36 class FileCheckException : public Exception
39 FileCheckException(const std::string &msg)
44 class CheckSumCheckException : public FileCheckException
49 class SignatureCheckException : public FileCheckException
55 * Built in file checkers
59 * \short Checks for a valid checksum and interacts with the user.
61 class ChecksumFileChecker
66 * \param checksum Checksum that validates the file
68 ChecksumFileChecker( const CheckSum &checksum );
70 * \short Try to validate the file
71 * \param file File to validate.
73 * \throws CheckSumCheckException if validation fails
75 void operator()( const Pathname &file ) const;
81 * \short Checks for the validity of a signature
83 class SignatureFileChecker
88 * \param signature Signature that validates the file
90 SignatureFileChecker( const Pathname &signature );
93 * Default Constructor.
94 * \short Signature for unsigned files
95 * Use it when you dont have a signature but you want
96 * to check the user to accept an unsigned file.
98 SignatureFileChecker();
102 * add a public key to the list of known keys
104 void addPublicKey( const Pathname &publickey, const KeyContext & keycontext = KeyContext());
106 * \short Try to validate the file
107 * \param file File to validate.
109 * \throws SignatureCheckException if validation fails
111 void operator()( const Pathname &file ) const;
119 * \short Checks for nothing
120 * Used as the default checker
122 class NullFileChecker
125 void operator()( const Pathname &file ) const;
129 * \short Checker composed of more checkers.
131 * Allows to create a checker composed of various
132 * checkers altothether. It will only
133 * validate if all the checkers validate.
136 * CompositeFileChecker com;
139 * fetcher.enqueue(location, com);
142 class CompositeFileChecker
145 void add( const FileChecker &checker );
147 * \throws FileCheckException if validation fails
149 void operator()( const Pathname &file ) const;
151 int checkersSize() const { return _checkers.size(); }
153 std::list<FileChecker> _checkers;
156 /** \relates FileChecker Stream output */
157 std::ostream & operator<<( std::ostream & str, const FileChecker & obj );
159 /////////////////////////////////////////////////////////////////
161 ///////////////////////////////////////////////////////////////////
162 #endif // ZYPP_FILECHECKER_H