libzypp 17.28.8
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
21#include <zypp/base/Iterable.h>
22#include <zypp/base/PtrTypes.h>
23#include <zypp/base/Exception.h>
25#include <zypp/Pathname.h>
26#include <zypp/Edition.h>
27#include <zypp/Date.h>
28
29struct _gpgme_key;
30struct _gpgme_subkey;
31
33namespace zypp
34{
35
36 namespace filesystem
37 {
38 class TmpFile;
39 }
40 class PublicKeyData;
41 class KeyManagerCtx;
42
48 {
49 public:
54 : Exception( "Bad Key Exception" )
55 {}
56
58 { return _keyfile; }
59
63 BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
64 : Exception( msg_r ), _keyfile(keyfile)
65 {}
67 virtual ~BadKeyException() throw() {};
68 private:
70 };
72
79 {
80 public:
83
85
87 explicit operator bool() const;
88
89 public:
91 std::string id() const;
92
94 Date created() const;
95
97 Date expires() const;
98
100 bool expired() const;
101
107 int daysToLive() const;
108
115 std::string asString() const;
116
117 private:
118 struct Impl;
120 friend class PublicKeyData;
121 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
122 PublicSubkeyData(const _gpgme_subkey *rawSubKeyData);
123 };
125
127 inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
128 { return str << obj.asString(); }
129
140 {
141 public:
144
146
148 explicit operator bool() const;
149
150 public:
152 std::string id() const;
153
155 std::string name() const;
156
158 std::string fingerprint() const;
159
161 std::string algoName() const;
162
164 Date created() const;
165
167 Date expires() const;
168
170 bool expired() const;
171
177 int daysToLive() const;
178
191 std::string expiresAsString() const;
192
194 std::string gpgPubkeyVersion() const;
195
197 std::string gpgPubkeyRelease() const;
198
200 std::string rpmName () const;
201
204 { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
205
212 std::string asString() const;
213
214 public:
216
218 bool hasSubkeys() const;
219
222
226 bool providesKey( const std::string & id_r ) const;
227
231 static bool isSafeKeyId( const std::string & id_r )
232 { return id_r.size() >= 16; }
233
234 public:
237
244 AsciiArt asciiArt() const;
245
246 private:
247 struct Impl;
249
250 friend class KeyManagerCtx;
251 static PublicKeyData fromGpgmeKey(_gpgme_key *data);
252
253 PublicKeyData(shared_ptr<Impl> data);
254 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
255 };
257
259 inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
260 { return str << obj.asString(); }
261
263 std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
264
266 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
267
269 inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
270 { return !( lhs == rhs ); }
271
284 {
285 public:
287 struct Impl;
288
289 public:
291 PublicKey();
292
301 explicit PublicKey( const Pathname & keyFile_r );
302
309 explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
310
311 ~PublicKey();
312
314 static PublicKey noThrow( const Pathname & keyFile_r );
315
316 public:
318 const PublicKeyData & keyData() const;
319
321
322 bool isValid() const
323 { return ! ( id().empty() || fingerprint().empty() ); }
324
325 std::string id() const;
326 std::string name() const;
327 std::string fingerprint() const;
328 std::string algoName() const;
329 Date created() const;
330 Date expires() const;
331 std::string expiresAsString() const;
332 bool expired() const;
333 int daysToLive() const;
334 std::string gpgPubkeyVersion() const;
335 std::string gpgPubkeyRelease() const;
336 std::string asString() const;
337 std::string rpmName () const;
338
340 { return keyData().gpgPubkeyEdition(); }
341
342 bool hasSubkeys() const
343 { return keyData().hasSubkeys(); }
344
346 { return keyData().subkeys(); }
347
348 bool providesKey( const std::string & id_r ) const
349 { return keyData().providesKey( id_r ); }
350
351 static bool isSafeKeyId( const std::string & id_r )
352 { return PublicKeyData::isSafeKeyId(id_r); }
353
354 public:
356
358 { return keyData().asciiArt(); }
359
360 public:
362 Pathname path() const;
363
365 const std::list<PublicKeyData> & hiddenKeys() const;
366
370 bool fileProvidesKey( const std::string & id_r ) const;
371
372 public:
373 bool operator==( const PublicKey & rhs ) const;
374 bool operator!=( const PublicKey & rhs ) const
375 { return not operator==( rhs ); }
376 bool operator==( const std::string & sid ) const;
377 bool operator!=( const std::string & sid ) const
378 { return not operator==( sid ); }
379
380 private:
381 friend class KeyRing;
383 PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
385 explicit PublicKey( const PublicKeyData & keyData_r );
386
387 private:
390 };
392
394 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
395 { return str << obj.asString(); }
396
398 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
399
401} // namespace zypp
403#endif // ZYPP_PUBLICKEY_H
Wrapper for GPGME.
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:48
BadKeyException(const std::string &msg_r, const Pathname &keyfile=Pathname())
Ctor taking message.
Definition: PublicKey.h:63
Pathname keyFile() const
Definition: PublicKey.h:57
virtual ~BadKeyException()
Dtor.
Definition: PublicKey.h:67
BadKeyException()
Ctor taking message.
Definition: PublicKey.h:53
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:146
Gpg key handling.
Definition: KeyRing.h:187
Class representing one GPG Public Keys data.
Definition: PublicKey.h:140
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:384
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:328
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:334
std::string name() const
Key name.
Definition: PublicKey.cc:319
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition: PublicKey.cc:367
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:337
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
NotEqual.
Definition: PublicKey.h:269
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition: PublicKey.cc:349
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:364
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:299
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:331
std::string algoName() const
Key algorithm string like RSA 2048
Definition: PublicKey.cc:325
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition: PublicKey.h:231
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:247
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:215
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:370
std::string id() const
Key ID.
Definition: PublicKey.cc:316
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:322
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:346
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:343
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition: PublicKey.cc:310
std::string expiresAsString() const
Definition: PublicKey.cc:340
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition: PublicKey.h:236
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition: PublicKey.cc:381
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:352
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition: PublicKey.h:203
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Stream output.
Definition: PublicKey.h:259
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:284
Pathname path() const
File containing the ASCII armored key.
Definition: PublicKey.cc:541
Edition gpgPubkeyEdition() const
!<
Definition: PublicKey.h:339
PublicKeyData::SubkeyIterator SubkeyIterator
Definition: PublicKey.h:320
std::string expiresAsString() const
Definition: PublicKey.cc:582
bool fileProvidesKey(const std::string &id_r) const
Extends providesKey to look at the hidden keys too.
Definition: PublicKey.cc:547
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:597
AsciiArt asciiArt() const
!<
Definition: PublicKey.h:357
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:389
PublicKeyData::AsciiArt AsciiArt
Definition: PublicKey.h:355
Date created() const
Definition: PublicKey.cc:570
PublicKey()
Default ctor.
Definition: PublicKey.cc:512
bool expired() const
Definition: PublicKey.cc:576
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
Definition: PublicKey.cc:544
static bool isSafeKeyId(const std::string &id_r)
!<
Definition: PublicKey.h:351
std::string rpmName() const
Definition: PublicKey.cc:594
std::string name() const
Definition: PublicKey.cc:561
Date expires() const
Definition: PublicKey.cc:573
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:538
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:588
std::string asString() const
Definition: PublicKey.cc:591
std::string fingerprint() const
Definition: PublicKey.cc:564
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Stream output.
Definition: PublicKey.h:394
std::string id() const
Definition: PublicKey.cc:558
std::string algoName() const
Definition: PublicKey.cc:567
int daysToLive() const
Definition: PublicKey.cc:579
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:585
bool operator!=(const std::string &sid) const
Definition: PublicKey.h:377
bool operator!=(const PublicKey &rhs) const
Definition: PublicKey.h:374
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition: PublicKey.cc:535
bool hasSubkeys() const
!<
Definition: PublicKey.h:342
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:348
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:345
bool isValid() const
Definition: PublicKey.h:322
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:79
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:384
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:118
std::string id() const
Subkey ID.
Definition: PublicKey.cc:179
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:161
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Stream output.
Definition: PublicKey.h:127
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:191
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:185
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:194
Date created() const
Creation date.
Definition: PublicKey.cc:182
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:188
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Definition: DrunkenBishop.h:62
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:128
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
bool operator==(const Url &lhs, const Url &rhs)
needed for find
Definition: Url.cc:875
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
PublicKeyData implementation.
Definition: PublicKey.cc:205
PublicKey implementation.
Definition: PublicKey.cc:408
PublicSubkeyData implementation.
Definition: PublicKey.cc:131
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459