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"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
27 * Functor signature used to check files.
28 * \param file File to check.
30 * \throws FileCheckException when the file does not
31 * validate and the user don't want to continue.
33 typedef function<void ( const Pathname &file )> FileChecker;
35 class FileCheckException : public Exception
38 FileCheckException(const std::string &msg)
43 class CheckSumCheckException : public FileCheckException
48 class SignatureCheckException : public FileCheckException
54 * Built in file checkers
58 * \short Checks for a valid checksum and interacts with the user.
60 class ChecksumFileChecker
65 * \param checksum Checksum that validates the file
67 ChecksumFileChecker( const CheckSum &checksum );
69 * \short Try to validate the file
70 * \param file File to validate.
72 * \throws CheckSumCheckException if validation fails
74 void operator()( const Pathname &file ) const;
80 * \short Checks for the validity of a signature
82 class SignatureFileChecker
87 * \param signature Signature that validates the file
89 SignatureFileChecker( const Pathname &signature,
90 const std::string &description = std::string() );
93 * Constructor for files not containing a signature
94 * \param description Description of the checker
96 SignatureFileChecker( const std::string &description );
99 * Default Constructor.
100 * \short Signature for unsigned files
101 * Use it when you dont have a signature but you want
102 * to check the user to accept an unsigned file.
104 SignatureFileChecker();
108 * add a public key to the list of known keys
110 void addPublicKey( const Pathname &publickey );
112 * \short Try to validate the file
113 * \param file File to validate.
115 * \throws SignatureCheckException if validation fails
117 void operator()( const Pathname &file ) const;
121 std::string _description;
125 * \short Checks for nothing
126 * Used as the default checker
128 class NullFileChecker
131 void operator()( const Pathname &file ) const;
135 * \short Checker composed of more checkers.
137 * Allows to create a checker composed of various
138 * checkers altothether. It will only
139 * validate if all the checkers validate.
142 * CompositeFileChecker com;
145 * fetcher.enqueue(location, com);
148 class CompositeFileChecker
151 void add( const FileChecker &checker );
153 * \throws FileCheckException if validation fails
155 void operator()( const Pathname &file ) const;
157 int checkersSize() const { return _checkers.size(); }
159 std::list<FileChecker> _checkers;
162 /** \relates FileChecker Stream output */
163 std::ostream & operator<<( std::ostream & str, const FileChecker & obj );
165 /////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////
168 #endif // ZYPP_FILECHECKER_H