libzypp: zypp/FileChecker.cc Source File

libzypp 17.38.11

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-core/base/Logger.h>
15#include <zypp/FileChecker.h>
16#include <zypp/ZYppFactory.h>
17#include <zypp/Digest.h>
18#include <zypp/KeyRing.h>
19#include <zypp/ng/workflows/keyringwf.h>
20#include <zypp/ng/workflows/checksumwf.h>
21#include <zypp/ng/workflows/signaturecheckwf.h>
22
23using std::endl;
24
25#undef ZYPP_BASE_LOGGER_LOGGROUP
26#define ZYPP_BASE_LOGGER_LOGGROUP "FileChecker"
27
29namespace zypp
30{
31
32 ChecksumFileChecker::ChecksumFileChecker( CheckSum checksum )
33 : _checksum(std::move(checksum))
34 {}
35
36 void ChecksumFileChecker::operator()( const Pathname &file ) const
37 {
38 const auto &res = zyppng::CheckSumWorkflow::verifyChecksum ( zyppng::Context::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
50 void CompositeFileChecker::operator()(const Pathname &file ) const
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
67 void CompositeFileChecker::add( const FileChecker &checker )
68 { _checkers.push_back(checker); }
69
70
71 SignatureFileChecker::SignatureFileChecker()
72 {}
73
74 SignatureFileChecker::SignatureFileChecker( Pathname signature_r )
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
89 auto res = zyppng::SignatureFileCheckWorkflow::verifySignature ( zyppng::Context::create(), keyring::VerifyFileContext(_verifyContext) );
90 if ( !res ) {
91 std::rethrow_exception( res.error ( ) );
92 }
93 self._verifyContext = std::move( *res );
94 }
95
96 keyring::VerifyFileContext &SignatureFileChecker::verifyContext()
97 {
98 return _verifyContext;
99 }
100
101 const keyring::VerifyFileContext &SignatureFileChecker::verifyContext() const
102 {
103 return _verifyContext;
104 }
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
FileChecker.h
KeyRing.h
Logger.h
MIL
#define MIL
Definition Logger.h:103
ERR
#define ERR
Definition Logger.h:105
ZYppFactory.h
checksumwf.h
zypp::CheckSum
Definition CheckSum.h:34
zypp::ChecksumFileChecker::operator()
void operator()(const Pathname &file) const
Try to validate the file.
Definition FileChecker.cc:36
zypp::ChecksumFileChecker::ChecksumFileChecker
ChecksumFileChecker(CheckSum checksum)
Constructor.
Definition FileChecker.cc:32
zypp::ChecksumFileChecker::_checksum
CheckSum _checksum
Definition FileChecker.h:64
zypp::CompositeFileChecker::_checkers
std::list< FileChecker > _checkers
Definition FileChecker.h:146
zypp::CompositeFileChecker::add
void add(const FileChecker &checker)
Definition FileChecker.cc:67
zypp::CompositeFileChecker::operator()
void operator()(const Pathname &file) const
Definition FileChecker.cc:50
zypp::NullFileChecker::operator()
void operator()(const Pathname &file) const
Definition FileChecker.cc:44
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:375
zypp::SignatureFileChecker::operator()
void operator()(const Pathname &file_r) const
Call KeyRing::verifyFileSignatureWorkflow to verify the file.
Definition FileChecker.cc:83
zypp::SignatureFileChecker::verifyContext
keyring::VerifyFileContext & verifyContext()
Definition FileChecker.cc:96
zypp::SignatureFileChecker::addPublicKey
void addPublicKey(const PublicKey &publickey_r)
Add a public key to the list of known keys.
Definition FileChecker.cc:80
zypp::SignatureFileChecker::_verifyContext
keyring::VerifyFileContext _verifyContext
Definition FileChecker.h:108
zypp::SignatureFileChecker::SignatureFileChecker
SignatureFileChecker()
Default Ctor for unsigned files.
Definition FileChecker.cc:71
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::keyring::VerifyFileContext
I/O context for KeyRing::verifyFileSignatureWorkflow.
Definition KeyRingContexts.h:30
zypp::keyring::VerifyFileContext::file
const Pathname & file() const
File to verify.
Definition KeyRingContexts.cc:73
keyringwf.h
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::getZYpp
ZYpp::Ptr getZYpp()
relates: ZYppFactory Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
zypp::FileChecker
function< void(const Pathname &file)> FileChecker
Functor signature used to check files.
Definition FileChecker.h:38
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zyppng::CheckSumWorkflow::verifyChecksum
MaybeAwaitable< expected< void > > verifyChecksum(ContextRef zyppCtx, zypp::CheckSum checksum, zypp::filesystem::Pathname file)
Definition checksumwf.cc:111
zyppng::SignatureFileCheckWorkflow::verifySignature
MaybeAwaitable< expected< zypp::keyring::VerifyFileContext > > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context)
Definition signaturecheckwf.cc:54
signaturecheckwf.h
Digest.h