libzypp 17.32.2
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 <map>
17#include <list>
18#include <set>
19#include <string>
20#include <utility>
21
22#include <zypp/base/Iterable.h>
23#include <zypp/base/PtrTypes.h>
24#include <zypp/base/Exception.h>
26#include <zypp/Pathname.h>
27#include <zypp/Edition.h>
28#include <zypp/Date.h>
29
30struct _gpgme_key;
31struct _gpgme_subkey;
32struct _gpgme_key_sig;
33
35namespace zypp
36{
37
38 namespace filesystem
39 {
40 class TmpFile;
41 }
42 class PublicKeyData;
43 class KeyManagerCtx;
44
50 {
51 public:
56 : Exception( "Bad Key Exception" )
57 {}
58
60 { return _keyfile; }
61
65 BadKeyException( const std::string & msg_r, Pathname keyfile = Pathname() )
66 : Exception( msg_r ), _keyfile(std::move(keyfile))
67 {}
69 ~BadKeyException() throw() override {};
70 private:
72 };
74
81 {
82 public:
85
87
89 explicit operator bool() const;
90
91 public:
93 std::string id() const;
94
96 Date created() const;
97
99 Date expires() const;
100
102 bool expired() const;
103
109 int daysToLive() const;
110
117 std::string asString() const;
118
119 private:
120 struct Impl;
122 friend class PublicKeyData;
123 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
125 };
127
129 inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
130 { return str << obj.asString(); }
131
138 {
139 public:
142
144
146 explicit operator bool() const;
147
148 public:
150 std::string id() const;
151
153 std::string name() const;
154
156 Date created() const;
157
159 Date expires() const;
160
162 bool expired() const;
163
169 int daysToLive() const;
170
172 bool inTrustedRing() const;
173
175 bool inKnownRing() const;
176
183 std::string asString() const;
184
185 private:
186 struct Impl;
188 friend class PublicKeyData;
189 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
191 };
193
195 inline std::ostream & operator<<( std::ostream & str, const PublicKeySignatureData & obj )
196 { return str << obj.asString(); }
197
208 {
209 public:
212
214
215 PublicKeyData(const PublicKeyData &) = default;
217 PublicKeyData &operator=(const PublicKeyData &) = default;
219
221 explicit operator bool() const;
222
223 public:
225 std::string id() const;
226
228 std::string name() const;
229
231 std::string fingerprint() const;
232
234 std::string algoName() const;
235
237 Date created() const;
238
240 Date expires() const;
241
243 bool expired() const;
244
250 int daysToLive() const;
251
264 std::string expiresAsString() const;
265
267 std::string gpgPubkeyVersion() const;
268
270 std::string gpgPubkeyRelease() const;
271
273 std::string rpmName () const;
274
278
285 std::string asString() const;
286
287 public:
290
292 bool hasSubkeys() const;
293
296
299
303 bool providesKey( const std::string & id_r ) const;
304
308 static bool isSafeKeyId( const std::string & id_r )
309 { return id_r.size() >= 16; }
310
311 public:
313 bool hasSignatures() const;
314
315 public:
318
325 AsciiArt asciiArt() const;
326
327 private:
328 struct Impl;
330
331 friend class KeyManagerCtx;
333
335 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
336 };
338
340 inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
341 { return str << obj.asString(); }
342
344 std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
345
347 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
348
350 inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
351 { return !( lhs == rhs ); }
352
365 {
366 public:
368 struct Impl;
369
370 public:
372 PublicKey();
373
382 explicit PublicKey( const Pathname & keyFile_r );
383
390 explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
391
392 ~PublicKey();
393
395 static PublicKey noThrow( const Pathname & keyFile_r );
396
397 public:
399 const PublicKeyData & keyData() const;
400
402
403 bool isValid() const
404 { return ! ( id().empty() || fingerprint().empty() ); }
405
406 std::string id() const;
407 std::string name() const;
408 std::string fingerprint() const;
409 std::string algoName() const;
410 Date created() const;
411 Date expires() const;
412 std::string expiresAsString() const;
413 bool expired() const;
414 int daysToLive() const;
415 std::string gpgPubkeyVersion() const;
416 std::string gpgPubkeyRelease() const;
417 std::string asString() const;
418 std::string rpmName () const;
419
422
423 bool hasSubkeys() const
424 { return keyData().hasSubkeys(); }
425
427 { return keyData().subkeys(); }
428
429 bool providesKey( const std::string & id_r ) const
430 { return keyData().providesKey( id_r ); }
431
432 static bool isSafeKeyId( const std::string & id_r )
434
435 public:
437
439 { return keyData().asciiArt(); }
440
441 public:
443 Pathname path() const;
444
446 const std::list<PublicKeyData> & hiddenKeys() const;
447
451 bool fileProvidesKey( const std::string & id_r ) const;
452
453 public:
454 bool operator==( const PublicKey & rhs ) const;
455 bool operator!=( const PublicKey & rhs ) const
456 { return not operator==( rhs ); }
457 bool operator==( const std::string & sid ) const;
458 bool operator!=( const std::string & sid ) const
459 { return not operator==( sid ); }
460
461 private:
462 friend class KeyRing;
466 explicit PublicKey( const PublicKeyData & keyData_r );
467
468 private:
471 };
473
475 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
476 { return str << obj.asString(); }
477
479 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
480
482} // namespace zypp
484#endif // ZYPP_PUBLICKEY_H
Wrapper for GPGME.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Exception thrown when the supplied key is not a valid gpg key.
Definition PublicKey.h:50
Pathname keyFile() const
Definition PublicKey.h:59
BadKeyException(const std::string &msg_r, Pathname keyfile=Pathname())
Ctor taking message.
Definition PublicKey.h:65
~BadKeyException() override
Dtor.
Definition PublicKey.h:69
BadKeyException()
Ctor taking message.
Definition PublicKey.h:55
Store and operate on date (time_t).
Definition Date.h:33
Edition represents [epoch:]version[-release]
Definition Edition.h:61
Base class for Exception.
Definition Exception.h:147
Gpg key handling.
Definition KeyRing.h:187
Class representing one GPG Public Keys data.
Definition PublicKey.h:208
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition PublicKey.cc:489
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Definition PublicKey.cc:472
Date created() const
Creation / last modification date (latest selfsig).
Definition PublicKey.cc:430
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:436
std::string name() const
Key name.
Definition PublicKey.cc:421
bool hasSignatures() const
Whether signatures is not empty.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition PublicKey.cc:469
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:439
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
NotEqual.
Definition PublicKey.h:350
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition PublicKey.cc:451
bool hasSubkeys() const
Whether subkeys is not empty.
Definition PublicKey.cc:466
PublicKeyData()
Default constructed: empty data.
Definition PublicKey.cc:401
const PublicSubkeyData * SubkeyIterator
Definition PublicKey.h:288
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:433
std::string algoName() const
Key algorithm string like RSA 2048
Definition PublicKey.cc:427
PublicKeyData(const PublicKeyData &)=default
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition PublicKey.h:308
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:329
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:475
std::string fingerprint() const
Key fingerprint.
Definition PublicKey.cc:424
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition PublicKey.cc:448
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition PublicKey.cc:445
PublicKeyData(PublicKeyData &&) noexcept=default
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition PublicKey.cc:412
std::string expiresAsString() const
Definition PublicKey.cc:442
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition PublicKey.cc:486
std::string asString() const
Simple string representation.
Definition PublicKey.cc:454
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition PublicKey.h:317
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition PublicKey.h:276
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Stream output.
Definition PublicKey.h:340
Class representing a signature on a GPG Public Key.
Definition PublicKey.h:138
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition PublicKey.cc:489
Date created() const
Creation date.
Definition PublicKey.cc:263
std::string asString() const
Simple string representation.
Definition PublicKey.cc:275
bool inKnownRing() const
Whether the key has been seen before.
Definition PublicKey.cc:293
PublicKeySignatureData()
Default constructed: empty data.
Definition PublicKey.cc:238
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:187
bool inTrustedRing() const
Whether the signature is trusted in rpmdb.
Definition PublicKey.cc:290
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
Definition PublicKey.cc:272
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:269
std::string id() const
The key ID of key used to create the signature.
Definition PublicKey.cc:257
std::ostream & operator<<(std::ostream &str, const PublicKeySignatureData &obj)
Stream output.
Definition PublicKey.h:195
std::string name() const
The user ID associated with this key, if present.
Definition PublicKey.cc:260
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:266
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:365
Pathname path() const
File containing the ASCII armored key.
Definition PublicKey.cc:646
Edition gpgPubkeyEdition() const
!<
Definition PublicKey.h:420
std::string expiresAsString() const
Definition PublicKey.cc:687
bool fileProvidesKey(const std::string &id_r) const
Extends providesKey to look at the hidden keys too.
Definition PublicKey.cc:652
bool operator==(const PublicKey &rhs) const
Definition PublicKey.cc:702
AsciiArt asciiArt() const
!<
Definition PublicKey.h:438
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition PublicKey.h:470
Date created() const
Definition PublicKey.cc:675
PublicKey()
Default ctor.
Definition PublicKey.cc:617
bool expired() const
Definition PublicKey.cc:681
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
Definition PublicKey.cc:649
static bool isSafeKeyId(const std::string &id_r)
!<
Definition PublicKey.h:432
std::string rpmName() const
Definition PublicKey.cc:699
std::string name() const
Definition PublicKey.cc:666
Date expires() const
Definition PublicKey.cc:678
const PublicKeyData & keyData() const
The public keys data (.
Definition PublicKey.cc:643
std::string gpgPubkeyRelease() const
Definition PublicKey.cc:693
std::string asString() const
Definition PublicKey.cc:696
std::string fingerprint() const
Definition PublicKey.cc:669
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Stream output.
Definition PublicKey.h:475
std::string id() const
Definition PublicKey.cc:663
std::string algoName() const
Definition PublicKey.cc:672
int daysToLive() const
Definition PublicKey.cc:684
std::string gpgPubkeyVersion() const
Definition PublicKey.cc:690
bool operator!=(const std::string &sid) const
Definition PublicKey.h:458
bool operator!=(const PublicKey &rhs) const
Definition PublicKey.h:455
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition PublicKey.cc:640
bool hasSubkeys() const
!<
Definition PublicKey.h:423
bool providesKey(const std::string &id_r) const
!<
Definition PublicKey.h:429
Iterable< SubkeyIterator > subkeys() const
!<
Definition PublicKey.h:426
bool isValid() const
Definition PublicKey.h:403
Class representing a GPG Public Keys subkeys.
Definition PublicKey.h:81
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition PublicKey.cc:489
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:121
std::string id() const
Subkey ID.
Definition PublicKey.cc:181
PublicSubkeyData()
Default constructed: empty data.
Definition PublicKey.cc:163
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Stream output.
Definition PublicKey.h:129
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:193
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:187
std::string asString() const
Simple string representation.
Definition PublicKey.cc:196
Date created() const
Creation date.
Definition PublicKey.cc:184
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:190
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:128
Definition Arch.h:364
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
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...
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
PublicKeyData implementation.
Definition PublicKey.cc:302
PublicKeySignatureData implementation.
Definition PublicKey.cc:207
PublicKey implementation.
Definition PublicKey.cc:513
PublicSubkeyData implementation.
Definition PublicKey.cc:133