libzypp: zypp/KeyRingContexts.cc Source File

libzypp 17.38.11

KeyRingContexts.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#include <optional>
12
13#include <zypp/KeyRingContexts.h>
14#include <zypp-core/base/LogTools.h>
15
17 namespace zypp::keyring
18{
24 class VerifyFileContext::Impl
25 {
26 public:
27 Impl()
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
37 void resetResults()
38 { _fileAccepted = _fileValidated = _signatureIdTrusted = false; _signatureId.clear(); }
39
40 // In:
41 Pathname _file;
42 Pathname _signature;
43 std::optional<std::string> _shortFile;
44 KeyContext _keyContext;
45 BuddyKeys _buddyKeys;
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
60 VerifyFileContext::VerifyFileContext()
61 : _pimpl( new Impl() )
62 {}
63 VerifyFileContext::VerifyFileContext( Pathname file_r )
64 : _pimpl( new Impl( std::move(file_r) ) )
65 {}
66 VerifyFileContext::VerifyFileContext( Pathname file_r, Pathname signature_r )
67 : _pimpl( new Impl( std::move(file_r), std::move(signature_r) ) )
68 {}
69 VerifyFileContext::~VerifyFileContext()
70 {}
71
72 // In:
73 const Pathname & VerifyFileContext::file() const
74 { return _pimpl->_file; }
75
76 void VerifyFileContext::file( Pathname file_r )
77 { _pimpl->_file = std::move(file_r); }
78
79 const Pathname & VerifyFileContext::signature() const
80 { return _pimpl->_signature; }
81
82 void VerifyFileContext::signature( Pathname signature_r )
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
91 const KeyContext & VerifyFileContext::keyContext() const
92 { return _pimpl->_keyContext; }
93
94 void VerifyFileContext::keyContext( KeyContext keyContext_r )
95 { _pimpl->_keyContext = std::move(keyContext_r); }
96
97 const VerifyFileContext::BuddyKeys & VerifyFileContext::buddyKeys() const
98 { return _pimpl->_buddyKeys; }
99
100 void VerifyFileContext::addBuddyKey( std::string sid_r )
101 { _pimpl->_buddyKeys.insert( std::move(sid_r) ); }
102
103 // Results:
104 void VerifyFileContext::resetResults()
105 { _pimpl->resetResults(); }
106
107 bool VerifyFileContext::fileAccepted() const
108 { return _pimpl->_fileAccepted; }
109
110 void VerifyFileContext::fileAccepted( bool yesno_r )
111 { _pimpl->_fileAccepted = yesno_r; }
112
113 bool VerifyFileContext::fileValidated() const
114 { return _pimpl->_fileValidated; }
115
116 void VerifyFileContext::fileValidated( bool yesno_r )
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
125 bool VerifyFileContext::signatureIdTrusted() const
126 { return _pimpl->_signatureIdTrusted; }
127
128 void VerifyFileContext::signatureIdTrusted( bool yesno_r )
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
142
KeyRingContexts.h
LogTools.h
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::basename
std::string basename() const
Return the last component of this path.
Definition Pathname.h:137
zypp::keyring::VerifyFileContext::Impl
Directly accessed by verifyFileSignatureWorkflow to set the result data.
Definition KeyRingContexts.cc:25
zypp::keyring::VerifyFileContext::Impl::resetResults
void resetResults()
Definition KeyRingContexts.cc:37
zypp::keyring::VerifyFileContext::Impl::_file
Pathname _file
Definition KeyRingContexts.cc:41
zypp::keyring::VerifyFileContext::Impl::Impl
Impl(Pathname file_r)
Definition KeyRingContexts.cc:29
zypp::keyring::VerifyFileContext::Impl::Impl
Impl(Pathname file_r, Pathname signature_r)
Definition KeyRingContexts.cc:32
zypp::keyring::VerifyFileContext::Impl::_signature
Pathname _signature
Definition KeyRingContexts.cc:42
zypp::keyring::VerifyFileContext::Impl::_keyContext
KeyContext _keyContext
Definition KeyRingContexts.cc:44
zypp::keyring::VerifyFileContext::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition KeyRingContexts.cc:56
zypp::keyring::VerifyFileContext::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::keyring::VerifyFileContext::Impl::_signatureIdTrusted
bool _signatureIdTrusted
Definition KeyRingContexts.cc:51
zypp::keyring::VerifyFileContext::Impl::_signatureId
std::string _signatureId
Definition KeyRingContexts.cc:50
zypp::keyring::VerifyFileContext::Impl::_fileValidated
bool _fileValidated
Definition KeyRingContexts.cc:49
zypp::keyring::VerifyFileContext::Impl::_shortFile
std::optional< std::string > _shortFile
Definition KeyRingContexts.cc:43
zypp::keyring::VerifyFileContext::Impl::_buddyKeys
BuddyKeys _buddyKeys
Definition KeyRingContexts.cc:45
zypp::keyring::VerifyFileContext::Impl::_fileAccepted
bool _fileAccepted
Definition KeyRingContexts.cc:48
zypp::keyring::VerifyFileContext::Impl::Impl
Impl()
Definition KeyRingContexts.cc:27
zypp::keyring::VerifyFileContext
I/O context for KeyRing::verifyFileSignatureWorkflow.
Definition KeyRingContexts.h:30
zypp::keyring::VerifyFileContext::fileValidated
bool fileValidated() const
Whether the signature was actually successfully verified.
Definition KeyRingContexts.cc:113
zypp::keyring::VerifyFileContext::BuddyKeys
std::set< std::string > BuddyKeys
List of key safe key ids to import IFF fileValidated.
Definition KeyRingContexts.h:64
zypp::keyring::VerifyFileContext::keyContext
const KeyContext & keyContext() const
KeyContext passed to callbacks
Definition KeyRingContexts.cc:91
zypp::keyring::VerifyFileContext::shortFile
std::string shortFile() const
Short name for file (default: basename).
Definition KeyRingContexts.cc:85
zypp::keyring::VerifyFileContext::_pimpl
RWCOW_pointer< Impl > _pimpl
Implementation.
Definition KeyRingContexts.h:93
zypp::keyring::VerifyFileContext::file
const Pathname & file() const
File to verify.
Definition KeyRingContexts.cc:73
zypp::keyring::VerifyFileContext::buddyKeys
const BuddyKeys & buddyKeys() const
Definition KeyRingContexts.cc:97
zypp::keyring::VerifyFileContext::signatureIdTrusted
bool signatureIdTrusted() const
Whether the SignatureId is in the trusted keyring (not temp.
Definition KeyRingContexts.cc:125
zypp::keyring::VerifyFileContext::VerifyFileContext
VerifyFileContext()
Ctor.
Definition KeyRingContexts.cc:60
zypp::keyring::VerifyFileContext::signature
const Pathname & signature() const
Detached signature or empty.
Definition KeyRingContexts.cc:79
zypp::keyring::VerifyFileContext::resetResults
void resetResults()
Reset all result values to safe defaults.
Definition KeyRingContexts.cc:104
zypp::keyring::VerifyFileContext::signatureId
const std::string & signatureId() const
The id of the gpg key which signed the file.
Definition KeyRingContexts.cc:119
zypp::keyring::VerifyFileContext::~VerifyFileContext
~VerifyFileContext()
Definition KeyRingContexts.cc:69
zypp::keyring::VerifyFileContext::fileAccepted
bool fileAccepted() const
May return true due to user interaction or global defaults even if the signature was not actually ver...
Definition KeyRingContexts.cc:107
zypp::keyring::VerifyFileContext::addBuddyKey
void addBuddyKey(std::string sid_r)
Definition KeyRingContexts.cc:100
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp::keyring
Definition KeyRingContexts.cc:18
zypp::keyring::operator<<
std::ostream & operator<<(std::ostream &str, const VerifyFileContext &obj)
relates: VerifyFileContext Stream output
Definition KeyRingContexts.cc:131
zypp::asString
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition Patch.cc:122
zypp::KeyContext
Definition KeyContext.h:9