libzypp 17.31.7
KeyRingContexts.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#include <optional>
12
14#include <zypp/base/LogTools.h>
15
18{
25 {
26 public:
28 {}
29 Impl( Pathname file_r )
30 : _file( std::move(file_r) )
31 {}
32 Impl( Pathname file_r, Pathname signature_r )
33 : _file( std::move(file_r) )
34 , _signature( std::move(signature_r) )
35 {}
36
39
40 // In:
43 std::optional<std::string> _shortFile;
46
47 // Results:
48 bool _fileAccepted = false;
49 bool _fileValidated = false;
50 std::string _signatureId;
51 bool _signatureIdTrusted = false;
52
53 private:
54 friend Impl * rwcowClone<Impl>( const Impl * rhs );
56 Impl * clone() const
57 { return new Impl( *this ); }
58 };
59
61 : _pimpl( new Impl() )
62 {}
64 : _pimpl( new Impl( std::move(file_r) ) )
65 {}
67 : _pimpl( new Impl( std::move(file_r), std::move(signature_r) ) )
68 {}
70 {}
71
72 // In:
74 { return _pimpl->_file; }
75
77 { _pimpl->_file = std::move(file_r); }
78
80 { return _pimpl->_signature; }
81
83 { _pimpl->_signature = std::move(signature_r); }
84
85 std::string VerifyFileContext::shortFile() const
86 { return _pimpl->_shortFile.has_value() ? _pimpl->_shortFile.value() : _pimpl->_file.basename(); }
87
88 void VerifyFileContext::shortFile( std::string shortFile_r )
89 { _pimpl->_shortFile = std::move(shortFile_r); }
90
92 { return _pimpl->_keyContext; }
93
95 { _pimpl->_keyContext = std::move(keyContext_r); }
96
98 { return _pimpl->_buddyKeys; }
99
100 void VerifyFileContext::addBuddyKey( std::string sid_r )
101 { _pimpl->_buddyKeys.insert( sid_r ); }
102
103 // Results:
105 { _pimpl->resetResults(); }
106
108 { return _pimpl->_fileAccepted; }
109
111 { _pimpl->_fileAccepted = yesno_r; }
112
114 { return _pimpl->_fileValidated; }
115
117 { _pimpl->_fileValidated = yesno_r; }
118
119 const std::string & VerifyFileContext::signatureId() const
120 { return _pimpl->_signatureId; }
121
122 void VerifyFileContext::signatureId( std::string signatureId_r )
123 { _pimpl->_signatureId = std::move(signatureId_r); }
124
126 { return _pimpl->_signatureIdTrusted; }
127
129 { _pimpl->_signatureIdTrusted = yesno_r; }
130
131 std::ostream & operator<<( std::ostream & str, const VerifyFileContext & obj )
132 {
133 return str << obj.file()
134 << "[" << obj.signature().basename()
135 << " accepted:" << asString( obj.fileAccepted() )
136 << ", validated:" << ( obj.fileValidated() ? ( obj.signatureIdTrusted() ? "trusted" : "true" ) : "false" )
137 << "(" << obj.signatureId() << ")"
138 << "]";;
139 }
140
141} // namespace zypp::keyring
std::string basename() const
Return the last component of this path.
Definition: Pathname.h:128
Directly accessed by verifyFileSignatureWorkflow to set the result data.
Impl(Pathname file_r, Pathname signature_r)
Impl * clone() const
clone for RWCOW_pointer
std::optional< std::string > _shortFile
I/O context for KeyRing::verifyFileSignatureWorkflow.
std::set< std::string > BuddyKeys
List of key safe key ids to import IFF fileValidated.
bool fileValidated() const
Whether the signature was actually successfully verified.
const KeyContext & keyContext() const
KeyContext passed to callbacks
std::string shortFile() const
Short name for file (default: basename).
RWCOW_pointer< Impl > _pimpl
Implementation.
const Pathname & file() const
File to verify.
const BuddyKeys & buddyKeys() const
bool signatureIdTrusted() const
Whether the SignatureId is in the trusted keyring (not temp.
const Pathname & signature() const
Detached signature or empty.
void resetResults()
Reset all result values to safe defaults.
const std::string & signatureId() const
The id of the gpg key which signed the file.
bool fileAccepted() const
May return true due to user interaction or global defaults even if the signature was not actually ver...
void addBuddyKey(std::string sid_r)
Definition: Arch.h:352
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const VerifyFileContext &obj)
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122