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();
104 * add a public key to the list of known keys
106 void addPublicKey( const PublicKey & publickey, const KeyContext & keycontext = KeyContext());
107 /** \overload Convenience taking the public keys pathname. */
108 void addPublicKey( const Pathname & publickey, const KeyContext & keycontext = KeyContext());
111 * \short Try to validate the file
112 * \param file File to validate.
114 * \throws SignatureCheckException if validation fails
116 void operator()( const Pathname &file ) const;
124 * \short Checks for nothing
125 * Used as the default checker
127 class NullFileChecker
130 void operator()( const Pathname &file ) const;
134 * \short Checker composed of more checkers.
136 * Allows to create a checker composed of various
137 * checkers altothether. It will only
138 * validate if all the checkers validate.
141 * CompositeFileChecker com;
144 * fetcher.enqueue(location, com);
147 class CompositeFileChecker
150 void add( const FileChecker &checker );
152 * \throws FileCheckException if validation fails
154 void operator()( const Pathname &file ) const;
156 int checkersSize() const { return _checkers.size(); }
158 std::list<FileChecker> _checkers;
161 /** \relates FileChecker Stream output */
162 std::ostream & operator<<( std::ostream & str, const FileChecker & obj );
164 /////////////////////////////////////////////////////////////////
166 ///////////////////////////////////////////////////////////////////
167 #endif // ZYPP_FILECHECKER_H