libzypp 17.35.11
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
276 Edition gpgPubkeyEdition() const
277 { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
278
285 std::string asString() const;
286
287 public:
290
292 bool hasSubkeys() const;
293
295 Iterable<SubkeyIterator> subkeys() const;
296
298 Iterable<KeySignatureIterator> signatures() const;
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;
332 static PublicKeyData fromGpgmeKey(_gpgme_key *data);
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 ) ZYPP_API;
345
347 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs ) ZYPP_API;
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
421 { return keyData().gpgPubkeyEdition(); }
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 ) ZYPP_API;
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
bool hasSignatures() const
Whether signatures is not empty.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition PublicKey.cc:469
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
NotEqual.
Definition PublicKey.h:350
bool hasSubkeys() const
Whether subkeys is not empty.
Definition PublicKey.cc:466
const PublicSubkeyData * SubkeyIterator
Definition PublicKey.h:288
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
PublicKeyData(PublicKeyData &&) noexcept=default
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition PublicKey.cc:486
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
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:187
std::ostream & operator<<(std::ostream &str, const PublicKeySignatureData &obj)
Stream output.
Definition PublicKey.h:195
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:365
Edition gpgPubkeyEdition() const
!<
Definition PublicKey.h:420
AsciiArt asciiArt() const
!<
Definition PublicKey.h:438
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition PublicKey.h:470
static bool isSafeKeyId(const std::string &id_r)
!<
Definition PublicKey.h:432
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Stream output.
Definition PublicKey.h:475
bool operator!=(const std::string &sid) const
Definition PublicKey.h:458
bool operator!=(const PublicKey &rhs) const
Definition PublicKey.h:455
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
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:121
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Stream output.
Definition PublicKey.h:129
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)
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:302
PublicKeySignatureData implementation.
Definition PublicKey.cc:207
PublicKey implementation.
Definition PublicKey.cc:513
PublicSubkeyData implementation.
Definition PublicKey.cc:133