libzypp 17.37.17
FileChecker.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <utility>
14#include <zypp/base/Logger.h>
15#include <zypp/FileChecker.h>
16#include <zypp/ZYppFactory.h>
17#include <zypp/Digest.h>
18#include <zypp/KeyRing.h>
22
23using std::endl;
24
25#undef ZYPP_BASE_LOGGER_LOGGROUP
26#define ZYPP_BASE_LOGGER_LOGGROUP "FileChecker"
27
29namespace zypp
30{
31
33 : _checksum(std::move(checksum))
34 {}
35
36 void ChecksumFileChecker::operator()( const Pathname &file ) const
37 {
38 const auto &res = zyppng::CheckSumWorkflow::verifyChecksum ( zyppng::SyncContext::create(), _checksum, file );
39 if ( !res ) {
40 std::rethrow_exception( res.error ( ) );
41 }
42 }
43
44 void NullFileChecker::operator()(const Pathname &file ) const
45 {
46 MIL << "+ null check on " << file << endl;
47 return;
48 }
49
51 {
52 //MIL << _checkers.size() << " checkers" << endl;
53 for ( std::list<FileChecker>::const_iterator it = _checkers.begin(); it != _checkers.end(); ++it )
54 {
55 if ( *it )
56 {
57 //MIL << "+ chk" << endl;
58 (*it)(file);
59 }
60 else
61 {
62 ERR << "Invalid checker" << endl;
63 }
64 }
65 }
66
68 { _checkers.push_back(checker); }
69
70
73
75 { _verifyContext.signature( std::move(signature_r) ); }
76
77 void SignatureFileChecker::addPublicKey( const Pathname & publickey_r )
78 { addPublicKey( PublicKey(publickey_r) ); }
79
80 void SignatureFileChecker::addPublicKey( const PublicKey & publickey_r )
81 { getZYpp()->keyRing()->importKey( publickey_r, false ); }
82
83 void SignatureFileChecker::operator()( const Pathname & file_r ) const
84 {
85 // const_cast because the workflow is allowed to store result values here
86 SignatureFileChecker & self { const_cast<SignatureFileChecker&>(*this) };
87 self._verifyContext.file( file_r );
88
90 if ( !res ) {
91 std::rethrow_exception( res.error ( ) );
92 }
93 self._verifyContext = std::move( *res );
94 }
95
100
105
106 /******************************************************************
107 **
108 ** FUNCTION NAME : operator<<
109 ** FUNCTION TYPE : std::ostream &
110 */
111 std::ostream & operator<<( std::ostream & str, const FileChecker & obj )
112 {
113 return str;
114 }
115
117} // namespace zypp
void operator()(const Pathname &file) const
Try to validate the file.
ChecksumFileChecker(CheckSum checksum)
Constructor.
std::list< FileChecker > _checkers
void add(const FileChecker &checker)
void operator()(const Pathname &file) const
void operator()(const Pathname &file) const
void operator()(const Pathname &file_r) const
Call KeyRing::verifyFileSignatureWorkflow to verify the file.
keyring::VerifyFileContext & verifyContext()
void addPublicKey(const PublicKey &publickey_r)
Add a public key to the list of known keys.
keyring::VerifyFileContext _verifyContext
SignatureFileChecker()
Default Ctor for unsigned files.
ZYpp::Ptr getZYpp()
Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
I/O context for KeyRing::verifyFileSignatureWorkflow.
const Pathname & file() const
File to verify.
Definition Arch.h:364
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
function< void(const Pathname &file)> FileChecker
Functor signature used to check files.
Definition FileChecker.h:38
expected< void > verifyChecksum(SyncContextRef zyppCtx, zypp::CheckSum checksum, zypp::Pathname file)
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
#define MIL
Definition Logger.h:100
#define ERR
Definition Logger.h:102