libzypp 17.38.3
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
21
25#include <zypp-core/Pathname.h>
26#include <zypp/Edition.h>
27#include <zypp-core/Date.h>
28
29struct _gpgme_key;
30struct _gpgme_subkey;
31struct _gpgme_key_sig;
32
34namespace zypp
35{
36
37 namespace filesystem
38 {
39 class TmpFile;
40 }
41 class PublicKeyData;
42 class KeyManagerCtx;
43
49 {
50 public:
55 : Exception( "Bad Key Exception" )
56 {}
57
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:
71 };
72
73
80 {
81 public:
84
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;
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
137 {
138 public:
141
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;
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
201 {
202 public:
205
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
271
278 std::string asString() const;
279
280 public:
283
285 bool hasSubkeys() const;
286
289
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:
311
318 AsciiArt asciiArt() const;
319
320 private:
321 struct Impl;
323
324 friend class KeyManagerCtx;
325 static PublicKeyData fromGpgmeKey(_gpgme_key *data);
326
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
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
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
414 { return keyData().gpgPubkeyEdition(); }
415
416 bool hasSubkeys() const
417 { return keyData().hasSubkeys(); }
418
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:
430
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:
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
Pathname keyFile() const
Definition PublicKey.h:58
BadKeyException(const std::string &msg_r, Pathname keyfile=Pathname())
Ctor taking message.
Definition PublicKey.h:64
~BadKeyException() override
Dtor.
Definition PublicKey.h:68
BadKeyException()
Ctor taking message.
Definition PublicKey.h:54
Store and operate on date (time_t).
Definition Date.h:33
Edition represents [epoch:]version[-release].
Definition Edition.h:61
Exception()
Default ctor.
Definition Exception.cc:94
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Definition PublicKey.cc:466
Date created() const
Creation / last modification date (latest selfsig).
Definition PublicKey.cc:424
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:430
std::string name() const
Key name.
Definition PublicKey.cc:415
bool hasSignatures() const
Whether signatures is not empty.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition PublicKey.cc:463
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:433
friend class KeyManagerCtx
Definition PublicKey.h:324
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
NotEqual.
Definition PublicKey.h:343
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition PublicKey.cc:445
bool hasSubkeys() const
Whether subkeys is not empty.
Definition PublicKey.cc:460
PublicKeyData()
Default constructed: empty data.
Definition PublicKey.cc:395
const PublicSubkeyData * SubkeyIterator
Definition PublicKey.h:281
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:427
std::string algoName() const
Key algorithm string like RSA 2048.
Definition PublicKey.cc:421
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:301
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:322
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
std::string fingerprint() const
Key fingerprint.
Definition PublicKey.cc:418
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created).
Definition PublicKey.cc:442
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id).
Definition PublicKey.cc:439
PublicKeyData(PublicKeyData &&) noexcept=default
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition PublicKey.cc:406
std::string expiresAsString() const
Definition PublicKey.cc:436
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition PublicKey.cc:480
std::string asString() const
Simple string representation.
Definition PublicKey.cc:448
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition PublicKey.h:310
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition PublicKey.h:269
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Stream output.
Definition PublicKey.h:333
const PublicKeySignatureData * KeySignatureIterator
Definition PublicKey.h:282
Class representing a signature on a GPG Public Key.
Definition PublicKey.h:137
Date created() const
Creation date.
Definition PublicKey.cc:263
std::string asString() const
Simple string representation.
Definition PublicKey.cc:275
PublicKeySignatureData()
Default constructed: empty data.
Definition PublicKey.cc:238
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:180
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:188
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:358
Edition gpgPubkeyEdition() const
!<
Definition PublicKey.h:413
PublicKeyData::AsciiArt AsciiArt
Definition PublicKey.h:429
AsciiArt asciiArt() const
!<
Definition PublicKey.h:431
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition PublicKey.h:463
PublicKey()
Default ctor.
Definition PublicKey.cc:611
static bool isSafeKeyId(const std::string &id_r)
!<
Definition PublicKey.h:425
const PublicKeyData & keyData() const
The public keys data (.
Definition PublicKey.cc:637
std::string asString() const
Definition PublicKey.cc:690
std::string fingerprint() const
Definition PublicKey.cc:663
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Stream output.
Definition PublicKey.h:468
std::string id() const
Definition PublicKey.cc:657
bool operator!=(const std::string &sid) const
Definition PublicKey.h:451
bool operator!=(const PublicKey &rhs) const
Definition PublicKey.h:448
PublicKeyData::SubkeyIterator SubkeyIterator
Definition PublicKey.h:394
friend class KeyRingImpl
Definition PublicKey.h:455
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition PublicKey.cc:634
bool hasSubkeys() const
!<
Definition PublicKey.h:416
bool providesKey(const std::string &id_r) const
!<
Definition PublicKey.h:422
Iterable< SubkeyIterator > subkeys() const
!<
Definition PublicKey.h:419
bool isValid() const
Definition PublicKey.h:396
Class representing a GPG Public Keys subkeys.
Definition PublicKey.h:80
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:120
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:128
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
friend class PublicKeyData
Definition PublicKey.h:121
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:118
Definition ansi.h:855
String related utilities and Regular expression matching.
Types and functions for filesystem operations.
Definition Glob.cc:24
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)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
PublicKeyData implementation.
Definition PublicKey.cc:296
PublicKeySignatureData implementation.
Definition PublicKey.cc:207
PublicKey implementation.
Definition PublicKey.cc:507
PublicSubkeyData implementation.
Definition PublicKey.cc:133
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469