libzypp 17.37.17
signaturecheckwf.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include "signaturecheckwf.h"
11#include "keyringwf.h"
12#include "logichelpers.h"
13
14#include <zypp/ZYppFactory.h>
17
18namespace zyppng {
19
20 namespace {
21
22 using namespace zyppng::operators;
23
24 template <class Executor, class OpType>
25 struct VerifySignatureLogic : public LogicBase<Executor,OpType> {
26
27 ZYPP_ENABLE_LOGIC_BASE(Executor,OpType);
28 using ZyppContextRefType = MaybeAsyncContextRef<OpType>;
29
30 VerifySignatureLogic( ZyppContextRefType &&zyppCtx, zypp::keyring::VerifyFileContext &&ctx )
31 : _zyppCtx( std::move(zyppCtx) )
32 , _verifyCtx( std::move(ctx) ) { }
33
34 MaybeAsyncRef<expected<zypp::keyring::VerifyFileContext>> execute () {
35
36 const zypp::Pathname & sig { _verifyCtx.signature() };
37 if ( not ( sig.empty() || zypp::PathInfo(sig).isExist() ) ) {
38 return makeReadyResult( expected<zypp::keyring::VerifyFileContext>::error(ZYPP_EXCPT_PTR( zypp::SignatureCheckException("Signature " + sig.asString() + " not found.") )));
39 }
40
41 MIL << "Checking " << _verifyCtx.file ()<< " file validity using digital signature.." << std::endl;
42
43 return KeyRingWorkflow::verifyFileSignature( _zyppCtx, zypp::keyring::VerifyFileContext( _verifyCtx ) )
44 | []( auto &&res ) {
45 if ( not res.first )
46 return expected<zypp::keyring::VerifyFileContext>::error( ZYPP_EXCPT_PTR( zypp::SignatureCheckException( "Signature verification failed for " + res.second.file().basename() ) ) );
47 return expected<zypp::keyring::VerifyFileContext>::success ( std::move( res.second ) );
48 };
49 }
50
51 protected:
52 ZyppContextRefType _zyppCtx;
53 zypp::keyring::VerifyFileContext _verifyCtx;
54 };
55 }
56
68}
const std::string & asString() const
String representation.
Definition Pathname.h:93
bool empty() const
Test for an empty path.
Definition Pathname.h:116
I/O context for KeyRing::verifyFileSignatureWorkflow.
static expected success(ConsParams &&...params)
Definition expected.h:115
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
std::pair< bool, zypp::keyring::VerifyFileContext > verifyFileSignature(SyncContextRef zyppContext, zypp::keyring::VerifyFileContext &&context_r)
Follows a signature verification interacting with the user.
Definition keyringwf.cc:361
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition asyncop.h:297
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
#define MIL
Definition Logger.h:100