libzypp 17.38.3
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"
13
14#include <zypp/ZYppFactory.h>
17
18namespace zyppng {
19
20 namespace {
21
22 using namespace zyppng::operators;
23
24 struct VerifySignatureLogic {
25
26 VerifySignatureLogic( ContextRef &&zyppCtx, zypp::keyring::VerifyFileContext &&ctx )
27 : _zyppCtx( std::move(zyppCtx) )
28 , _verifyCtx( std::move(ctx) ) { }
29
30 MaybeAwaitable<expected<zypp::keyring::VerifyFileContext>> execute () {
31
32 const zypp::Pathname & sig { _verifyCtx.signature() };
33 if ( not ( sig.empty() || zypp::PathInfo(sig).isExist() ) ) {
34 return makeReadyTask( expected<zypp::keyring::VerifyFileContext>::error(ZYPP_EXCPT_PTR( zypp::SignatureCheckException("Signature " + sig.asString() + " not found.") )));
35 }
36
37 MIL << "Checking " << _verifyCtx.file ()<< " file validity using digital signature.." << std::endl;
38
39 return KeyRingWorkflow::verifyFileSignature( _zyppCtx, zypp::keyring::VerifyFileContext( _verifyCtx ) )
40 | []( auto &&res ) {
41 if ( not res.first )
42 return expected<zypp::keyring::VerifyFileContext>::error( ZYPP_EXCPT_PTR( zypp::SignatureCheckException( "Signature verification failed for " + res.second.file().basename() ) ) );
43 return expected<zypp::keyring::VerifyFileContext>::success ( std::move( res.second ) );
44 };
45 }
46
47 protected:
48 ContextRef _zyppCtx;
49 zypp::keyring::VerifyFileContext _verifyCtx;
50 };
51 }
52
54 MaybeAwaitable<expected<zypp::keyring::VerifyFileContext> > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context )
55 {
56 VerifySignatureLogic impl( std::move(ctx), std::move(context) );
57 zypp_co_return zypp_co_await( impl.execute () );
58 }
59 }
60}
#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
const std::string & asString() const
String representation.
Definition Pathname.h:94
bool empty() const
Test for an empty path.
Definition Pathname.h:117
I/O context for KeyRing::verifyFileSignatureWorkflow.
static expected success(ConsParams &&...params)
Definition expected.h:178
MaybeAwaitable< std::pair< bool, zypp::keyring::VerifyFileContext > > verifyFileSignature(ContextRef zyppContext, zypp::keyring::VerifyFileContext &&context_r)
Follows a signature verification interacting with the user.
Definition keyringwf.cc:346
MaybeAwaitable< expected< zypp::keyring::VerifyFileContext > > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context)