libzypp: zypp/ng/workflows/signaturecheckwf.cc Source File

libzypp 17.36.6

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>
15#include <zypp-core/fs/PathInfo.h>
16#include <zypp-media/filecheckexception.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
57 namespace SignatureFileCheckWorkflow {
58 expected<zypp::keyring::VerifyFileContext> verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context )
59 {
60 return SimpleExecutor<VerifySignatureLogic, SyncOp<expected<zypp::keyring::VerifyFileContext>>>::run( std::move(ctx), std::move(context) );
61 }
62
63 AsyncOpRef<expected<zypp::keyring::VerifyFileContext> > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context )
64 {
65 return SimpleExecutor<VerifySignatureLogic, AsyncOp<expected<zypp::keyring::VerifyFileContext>>>::run( std::move(ctx), std::move(context) );
66 }
67 }
68}
ZYppFactory.h
zypp::keyring::VerifyFileContext
I/O context for KeyRing::verifyFileSignatureWorkflow.
Definition KeyRingContexts.h:30
zyppng::expected
Definition expected.h:27
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:115
zyppng::expected::error
E & error()
Definition expected.h:225
filecheckexception.h
keyringwf.h
logichelpers.h
ZYPP_ENABLE_LOGIC_BASE
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
Definition logichelpers.h:223
zyppng::KeyRingWorkflow::verifyFileSignature
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:332
zyppng::SignatureFileCheckWorkflow
Definition signaturecheckwf.cc:57
zyppng::SignatureFileCheckWorkflow::verifySignature
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
Definition signaturecheckwf.cc:58
zyppng
Definition MediaCurl2.h:22
zyppng::makeReadyResult
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition asyncop.h:297
zyppng::AsyncOpRef
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
signaturecheckwf.h
zyppng::LogicBase
Definition logichelpers.h:161
zyppng::SimpleExecutor
Definition logichelpers.h:212
ZYPP_EXCPT_PTR
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:428
MIL
#define MIL
Definition Logger.h:100
PathInfo.h