X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=zypp%2FFileChecker.h;h=9ec04d5fedf32607eaa133bf2925e0ffeeafbb88;hb=HEAD;hp=4b961266df4b2856420a550d0ff52638ca68b19d;hpb=bddd1430702215e324e39332435a151b301463bc;p=platform%2Fupstream%2Flibzypp.git diff --git a/zypp/FileChecker.h b/zypp/FileChecker.h index 4b96126..ffbd854 100644 --- a/zypp/FileChecker.h +++ b/zypp/FileChecker.h @@ -14,16 +14,19 @@ #include #include -#include "zypp/base/Exception.h" -#include "zypp/base/Function.h" -#include "zypp/PathInfo.h" -#include "zypp/CheckSum.h" -#include "zypp/KeyContext.h" +#include +#include +#include +#include +#include +#include /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// + class PublicKey; + /** * Functor signature used to check files. * \param file File to check. @@ -32,7 +35,7 @@ namespace zypp * validate and the user don't want to continue. */ typedef function FileChecker; - + class FileCheckException : public Exception { public: @@ -40,27 +43,34 @@ namespace zypp : Exception(msg) {} }; - + class CheckSumCheckException : public FileCheckException { - //TODO + public: + CheckSumCheckException(const std::string &msg) + : FileCheckException(msg) + {} }; - + class SignatureCheckException : public FileCheckException { - //TODO + public: + SignatureCheckException(const std::string &msg) + : FileCheckException(msg) + {} }; - + /** * Built in file checkers */ - + /** * \short Checks for a valid checksum and interacts with the user. */ class ChecksumFileChecker { public: + typedef CheckSumCheckException ExceptionType; /** * Constructor. * \param checksum Checksum that validates the file @@ -76,13 +86,16 @@ namespace zypp private: CheckSum _checksum; }; - + /** * \short Checks for the validity of a signature */ class SignatureFileChecker { public: + typedef SignatureCheckException ExceptionType; + + public: /** * Constructor. * \param signature Signature that validates the file @@ -97,22 +110,59 @@ namespace zypp */ SignatureFileChecker(); + /** + * Set context for this checker. + * + * Use this method if you're not adding the key (with context) via + * one of the addPublicKey methods. The addPublicKey method overwrites + * the context. + */ + void setKeyContext(const KeyContext & keycontext); + + /** Return the current context */ + const KeyContext & keyContext() const + { return _context; } + + /** Return whether the last file passed to \ref operator() was accepted. + * If this is \ref false \ref operator() was not invoked or threw a + * \ref SignatureCheckException. + */ + bool fileAccepted() const + { return _fileAccepted; } + + /** Return whether the last file passed to \ref operator() was actually sucessfully verified. + * If this is \c false but \ref fileAccepted, the file was accepted due to user interaction or + * global settings, but the signature was not verified. + */ + bool fileValidated() const + { return _fileValidated; } /** * add a public key to the list of known keys */ - void addPublicKey( const Pathname &publickey, const KeyContext & keycontext = KeyContext()); + void addPublicKey( const PublicKey & publickey, const KeyContext & keycontext = KeyContext()); + /** \overload Convenience taking the public keys pathname. */ + void addPublicKey( const Pathname & publickey, const KeyContext & keycontext = KeyContext()); + /** - * \short Try to validate the file - * \param file File to validate. - * - * \throws SignatureCheckException if validation fails - */ + * Calls \ref KeyRing::verifyFileSignatureWorkflow to verify the file. + * + * Keep in mind the the workflow may return \c true (file accepted) due to user interaction + * or global defaults even if a signature was not actually sucessfully verified. Whether a + * signature was actually sucessfully verified can be determined by checking \ref fileValidated + * which is invokes IFF a signature for this file actually validated. + * + * \param file File to validate.fileValidated + * + * \throws SignatureCheckException if validation fails + */ void operator()( const Pathname &file ) const; protected: Pathname _signature; KeyContext _context; + mutable DefaultIntegral _fileAccepted; + mutable DefaultIntegral _fileValidated; }; /** @@ -124,10 +174,10 @@ namespace zypp public: void operator()( const Pathname &file ) const; }; - + /** * \short Checker composed of more checkers. - * + * * Allows to create a checker composed of various * checkers altothether. It will only * validate if all the checkers validate.