libzypp 17.38.5

PublicKey.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_PUBLICKEY_H
13#define ZYPP_PUBLICKEY_H
14
15#include <iosfwd>
16#include <list>
17#include <string>
18#include <utility>
19
20#include <zypp-common/base/DrunkenBishop.h>
21
22#include <zypp-core/base/Iterable.h>
23#include <zypp-core/base/PtrTypes.h>
24#include <zypp-core/base/Exception.h>
25#include <zypp-core/Pathname.h>
26#include <zypp/Edition.h>
27#include <zypp-core/Date.h>
28
29 struct _gpgme_key;
30 struct _gpgme_subkey;
31 struct _gpgme_key_sig;
32
34 namespace zypp
35{
36
37 namespace filesystem
38 {
39 class TmpFile;
40 }
41 class PublicKeyData;
42 class KeyManagerCtx;
43
48 class ZYPP_API BadKeyException : public Exception
49 {
50 public:
54 BadKeyException()
55 : Exception( "Bad Key Exception" )
56 {}
57
58 Pathname keyFile() const
59 { return _keyfile; }
60
64 BadKeyException( const std::string & msg_r, Pathname keyfile = Pathname() )
65 : Exception( msg_r ), _keyfile(std::move(keyfile))
66 {}
67
68 ~BadKeyException() throw() override {};
69 private:
70 Pathname _keyfile;
71 };
72
73
79 class ZYPP_API PublicSubkeyData
80 {
81 public:
83 PublicSubkeyData();
84
85 ~PublicSubkeyData();
86
88 explicit operator bool() const;
89
90 public:
92 std::string id() const;
93
95 Date created() const;
96
98 Date expires() const;
99
101 bool expired() const;
102
108 int daysToLive() const;
109
116 std::string asString() const;
117
118 private:
119 struct Impl;
120 RWCOW_pointer<Impl> _pimpl;
121 friend class PublicKeyData;
122 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
123 PublicSubkeyData(const _gpgme_subkey *rawSubKeyData);
124 };
125
126
128 inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
129 { return str << obj.asString(); }
130
136 class ZYPP_API PublicKeySignatureData
137 {
138 public:
140 PublicKeySignatureData();
141
142 ~PublicKeySignatureData();
143
145 explicit operator bool() const;
146
147 public:
149 std::string id() const;
150
152 std::string name() const;
153
155 Date created() const;
156
158 Date expires() const;
159
161 bool expired() const;
162
168 int daysToLive() const;
169
176 std::string asString() const;
177
178 private:
179 struct Impl;
180 RWCOW_pointer<Impl> _pimpl;
181 friend class PublicKeyData;
182 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
183 PublicKeySignatureData(const _gpgme_key_sig *rawKeySignatureData);
184 };
185
186
188 inline std::ostream & operator<<( std::ostream & str, const PublicKeySignatureData & obj )
189 { return str << obj.asString(); }
190
200 class ZYPP_API PublicKeyData
201 {
202 public:
204 PublicKeyData();
205
206 ~PublicKeyData();
207
208 PublicKeyData(const PublicKeyData &) = default;
209 PublicKeyData(PublicKeyData &&) noexcept = default;
210 PublicKeyData &operator=(const PublicKeyData &) = default;
211 PublicKeyData &operator=(PublicKeyData &&) noexcept = default;
212
214 explicit operator bool() const;
215
216 public:
218 std::string id() const;
219
221 std::string name() const;
222
224 std::string fingerprint() const;
225
227 std::string algoName() const;
228
230 Date created() const;
231
233 Date expires() const;
234
236 bool expired() const;
237
243 int daysToLive() const;
244
257 std::string expiresAsString() const;
258
260 std::string gpgPubkeyVersion() const;
261
263 std::string gpgPubkeyRelease() const;
264
266 std::string rpmName () const;
267
269 Edition gpgPubkeyEdition() const
270 { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
271
278 std::string asString() const;
279
280 public:
281 using SubkeyIterator = const PublicSubkeyData *;
282 using KeySignatureIterator = const PublicKeySignatureData *;
283
285 bool hasSubkeys() const;
286
288 Iterable<SubkeyIterator> subkeys() const;
289
291 Iterable<KeySignatureIterator> signatures() const;
292
296 bool providesKey( const std::string & id_r ) const;
297
301 static bool isSafeKeyId( const std::string & id_r )
302 { return id_r.size() >= 16; }
303
304 public:
306 bool hasSignatures() const;
307
308 public:
310 using AsciiArt = base::DrunkenBishop;
311
318 AsciiArt asciiArt() const;
319
320 private:
321 struct Impl;
322 RWCOW_pointer<Impl> _pimpl;
323
324 friend class KeyManagerCtx;
325 static PublicKeyData fromGpgmeKey(_gpgme_key *data);
326
327 PublicKeyData(shared_ptr<Impl> data);
328 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
329 };
330
331
333 inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
334 { return str << obj.asString(); }
335
337 std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj ) ZYPP_API;
338
340 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs ) ZYPP_API;
341
343 inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
344 { return !( lhs == rhs ); }
345
357 class ZYPP_API PublicKey
358 {
359 public:
361 struct Impl;
362
363 public:
365 PublicKey();
366
375 explicit PublicKey( const Pathname & keyFile_r );
376
383 explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
384
385 ~PublicKey();
386
388 static PublicKey noThrow( const Pathname & keyFile_r );
389
390 public:
392 const PublicKeyData & keyData() const;
393
394 using SubkeyIterator = PublicKeyData::SubkeyIterator;
395
396 bool isValid() const
397 { return ! ( id().empty() || fingerprint().empty() ); }
398
399 std::string id() const;
400 std::string name() const;
401 std::string fingerprint() const;
402 std::string algoName() const;
403 Date created() const;
404 Date expires() const;
405 std::string expiresAsString() const;
406 bool expired() const;
407 int daysToLive() const;
408 std::string gpgPubkeyVersion() const;
409 std::string gpgPubkeyRelease() const;
410 std::string asString() const;
411 std::string rpmName () const;
412
413 Edition gpgPubkeyEdition() const
414 { return keyData().gpgPubkeyEdition(); }
415
416 bool hasSubkeys() const
417 { return keyData().hasSubkeys(); }
418
419 Iterable<SubkeyIterator> subkeys() const
420 { return keyData().subkeys(); }
421
422 bool providesKey( const std::string & id_r ) const
423 { return keyData().providesKey( id_r ); }
424
425 static bool isSafeKeyId( const std::string & id_r )
426 { return PublicKeyData::isSafeKeyId(id_r); }
427
428 public:
429 using AsciiArt = PublicKeyData::AsciiArt;
430
431 AsciiArt asciiArt() const
432 { return keyData().asciiArt(); }
433
434 public:
436 Pathname path() const;
437
439 const std::list<PublicKeyData> & hiddenKeys() const;
440
444 bool fileProvidesKey( const std::string & id_r ) const;
445
446 public:
447 bool operator==( const PublicKey & rhs ) const;
448 bool operator!=( const PublicKey & rhs ) const
449 { return not operator==( rhs ); }
450 bool operator==( const std::string & sid ) const;
451 bool operator!=( const std::string & sid ) const
452 { return not operator==( sid ); }
453
454 private:
455 friend class KeyRingImpl;
457 PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
459 explicit PublicKey( const PublicKeyData & keyData_r );
460
461 private:
463 RWCOW_pointer<Impl> _pimpl;
464 };
465
466
468 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
469 { return str << obj.asString(); }
470
472 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj ) ZYPP_API;
473
475} // namespace zypp
477#endif // ZYPP_PUBLICKEY_H
Date.h
DrunkenBishop.h
Edition.h
Exception.h
Iterable.h
Pathname.h
PtrTypes.h
bool
shared_ptr
zypp::BadKeyException::keyFile
Pathname keyFile() const
Definition PublicKey.h:58
zypp::BadKeyException::BadKeyException
BadKeyException(const std::string &msg_r, Pathname keyfile=Pathname())
Ctor taking message.
Definition PublicKey.h:64
zypp::BadKeyException::~BadKeyException
~BadKeyException() override
Dtor.
Definition PublicKey.h:68
zypp::BadKeyException::_keyfile
Pathname _keyfile
Definition PublicKey.h:70
zypp::BadKeyException::BadKeyException
BadKeyException()
Ctor taking message.
Definition PublicKey.h:54
zypp::Date
Store and operate on date (time_t).
Definition Date.h:33
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:61
zypp::Exception::Exception
Exception()
Default ctor.
Definition Exception.cc:94
zypp::Iterable
Definition Iterable.h:37
zypp::KeyManagerCtx
Definition KeyManager.h:31
zypp::PublicKeyData
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
zypp::PublicKeyData::signatures
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Definition PublicKey.cc:466
zypp::PublicKeyData::created
Date created() const
Creation / last modification date (latest selfsig).
Definition PublicKey.cc:424
zypp::PublicKeyData::expired
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:430
zypp::PublicKeyData::name
std::string name() const
Key name.
Definition PublicKey.cc:415
zypp::PublicKeyData::hasSignatures
bool hasSignatures() const
Whether signatures is not empty.
zypp::PublicKeyData::subkeys
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition PublicKey.cc:463
zypp::PublicKeyData::daysToLive
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:433
zypp::PublicKeyData::KeyManagerCtx
friend class KeyManagerCtx
Definition PublicKey.h:324
zypp::PublicKeyData::operator!=
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
NotEqual.
Definition PublicKey.h:343
zypp::PublicKeyData::rpmName
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition PublicKey.cc:445
zypp::PublicKeyData::hasSubkeys
bool hasSubkeys() const
Whether subkeys is not empty.
Definition PublicKey.cc:460
zypp::PublicKeyData::PublicKeyData
PublicKeyData()
Default constructed: empty data.
Definition PublicKey.cc:395
zypp::PublicKeyData::SubkeyIterator
const PublicSubkeyData * SubkeyIterator
Definition PublicKey.h:281
zypp::PublicKeyData::expires
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:427
zypp::PublicKeyData::algoName
std::string algoName() const
Key algorithm string like RSA 2048.
Definition PublicKey.cc:421
zypp::PublicKeyData::PublicKeyData
PublicKeyData(const PublicKeyData &)=default
zypp::PublicKeyData::isSafeKeyId
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition PublicKey.h:301
zypp::PublicKeyData::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:322
zypp::PublicKeyData::providesKey
bool providesKey(const std::string &id_r) const
Whether id_r is the id or fingerprint of the primary key or of a subkey.
Definition PublicKey.cc:469
zypp::PublicKeyData::fingerprint
std::string fingerprint() const
Key fingerprint.
Definition PublicKey.cc:418
zypp::PublicKeyData::gpgPubkeyRelease
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created).
Definition PublicKey.cc:442
zypp::PublicKeyData::gpgPubkeyVersion
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id).
Definition PublicKey.cc:439
zypp::PublicKeyData::PublicKeyData
PublicKeyData(PublicKeyData &&) noexcept=default
zypp::PublicKeyData::fromGpgmeKey
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition PublicKey.cc:406
zypp::PublicKeyData::expiresAsString
std::string expiresAsString() const
Definition PublicKey.cc:436
zypp::PublicKeyData::asciiArt
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition PublicKey.cc:480
zypp::PublicKeyData::asString
std::string asString() const
Simple string representation.
Definition PublicKey.cc:448
zypp::PublicKeyData::AsciiArt
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition PublicKey.h:310
zypp::PublicKeyData::gpgPubkeyEdition
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition PublicKey.h:269
zypp::PublicKeyData::operator<<
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Stream output.
Definition PublicKey.h:333
zypp::PublicKeyData::KeySignatureIterator
const PublicKeySignatureData * KeySignatureIterator
Definition PublicKey.h:282
zypp::PublicKeySignatureData
Class representing a signature on a GPG Public Key.
Definition PublicKey.h:137
zypp::PublicKeySignatureData::created
Date created() const
Creation date.
Definition PublicKey.cc:263
zypp::PublicKeySignatureData::asString
std::string asString() const
Simple string representation.
Definition PublicKey.cc:275
zypp::PublicKeySignatureData::PublicKeySignatureData
PublicKeySignatureData()
Default constructed: empty data.
Definition PublicKey.cc:238
zypp::PublicKeySignatureData::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:180
zypp::PublicKeySignatureData::daysToLive
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
Definition PublicKey.cc:272
zypp::PublicKeySignatureData::expired
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:269
zypp::PublicKeySignatureData::id
std::string id() const
The key ID of key used to create the signature.
Definition PublicKey.cc:257
zypp::PublicKeySignatureData::operator<<
std::ostream & operator<<(std::ostream &str, const PublicKeySignatureData &obj)
Stream output.
Definition PublicKey.h:188
zypp::PublicKeySignatureData::name
std::string name() const
The user ID associated with this key, if present.
Definition PublicKey.cc:260
zypp::PublicKeySignatureData::expires
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:266
zypp::PublicKeySignatureData::PublicKeyData
friend class PublicKeyData
Definition PublicKey.h:181
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:358
zypp::PublicKey::gpgPubkeyEdition
Edition gpgPubkeyEdition() const
!<
Definition PublicKey.h:413
zypp::PublicKey::AsciiArt
PublicKeyData::AsciiArt AsciiArt
Definition PublicKey.h:429
zypp::PublicKey::asciiArt
AsciiArt asciiArt() const
!<
Definition PublicKey.h:431
zypp::PublicKey::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition PublicKey.h:463
zypp::PublicKey::PublicKey
PublicKey()
Default ctor.
Definition PublicKey.cc:611
zypp::PublicKey::isSafeKeyId
static bool isSafeKeyId(const std::string &id_r)
!<
Definition PublicKey.h:425
zypp::PublicKey::keyData
const PublicKeyData & keyData() const
The public keys data (.
Definition PublicKey.cc:637
zypp::PublicKey::asString
std::string asString() const
Definition PublicKey.cc:690
zypp::PublicKey::fingerprint
std::string fingerprint() const
Definition PublicKey.cc:663
zypp::PublicKey::operator<<
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Stream output.
Definition PublicKey.h:468
zypp::PublicKey::id
std::string id() const
Definition PublicKey.cc:657
zypp::PublicKey::operator!=
bool operator!=(const std::string &sid) const
Definition PublicKey.h:451
zypp::PublicKey::operator!=
bool operator!=(const PublicKey &rhs) const
Definition PublicKey.h:448
zypp::PublicKey::SubkeyIterator
PublicKeyData::SubkeyIterator SubkeyIterator
Definition PublicKey.h:394
zypp::PublicKey::KeyRingImpl
friend class KeyRingImpl
Definition PublicKey.h:455
zypp::PublicKey::noThrow
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition PublicKey.cc:634
zypp::PublicKey::hasSubkeys
bool hasSubkeys() const
!<
Definition PublicKey.h:416
zypp::PublicKey::providesKey
bool providesKey(const std::string &id_r) const
!<
Definition PublicKey.h:422
zypp::PublicKey::subkeys
Iterable< SubkeyIterator > subkeys() const
!<
Definition PublicKey.h:419
zypp::PublicKey::isValid
bool isValid() const
Definition PublicKey.h:396
zypp::PublicSubkeyData
Class representing a GPG Public Keys subkeys.
Definition PublicKey.h:80
zypp::PublicSubkeyData::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:120
zypp::PublicSubkeyData::id
std::string id() const
Subkey ID.
Definition PublicKey.cc:181
zypp::PublicSubkeyData::PublicSubkeyData
PublicSubkeyData()
Default constructed: empty data.
Definition PublicKey.cc:163
zypp::PublicSubkeyData::operator<<
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Stream output.
Definition PublicKey.h:128
zypp::PublicSubkeyData::daysToLive
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:193
zypp::PublicSubkeyData::expires
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:187
zypp::PublicSubkeyData::PublicKeyData
friend class PublicKeyData
Definition PublicKey.h:121
zypp::PublicSubkeyData::asString
std::string asString() const
Simple string representation.
Definition PublicKey.cc:196
zypp::PublicSubkeyData::created
Date created() const
Creation date.
Definition PublicKey.cc:184
zypp::PublicSubkeyData::expired
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:190
zypp::base::DrunkenBishop
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Definition DrunkenBishop.h:62
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::TmpFile
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:118
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp::filesystem
Types and functions for filesystem operations.
Definition Glob.cc:24
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::operator==
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SetRelationMixin.h:84
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition Capability.cc:588
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zypp::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
zypp::PublicKeyData::Impl
PublicKeyData implementation.
Definition PublicKey.cc:296
zypp::PublicKeySignatureData::Impl
PublicKeySignatureData implementation.
Definition PublicKey.cc:207
zypp::PublicKey::Impl
PublicKey implementation.
Definition PublicKey.cc:507
zypp::PublicSubkeyData::Impl
PublicSubkeyData implementation.
Definition PublicKey.cc:133
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469