29 #define GPG_BINARY "/usr/bin/gpg2"
39 inline bool isExpired(
const Date & expires_r )
40 {
return( expires_r && expires_r <
Date::now() ); }
42 inline int hasDaysToLive(
const Date & expires_r )
48 if ( exp < 0 ) ret -= 1;
54 inline std::string expiresDetail(
const Date & expires_r )
60 str <<
_(
"does not expire");
62 else if ( isExpired( expires_r ) )
65 str << ( str::Format(
_(
"expired: %1%") ) % expires_r.printDate() );
70 str << ( str::Format(
_(
"expires: %1%") ) % expires_r.printDate() );
75 inline std::string expiresDetailVerbose(
const Date & expires_r )
79 return _(
"(does not expire)");
81 std::string ret( expires_r.asString() );
82 int ttl( hasDaysToLive( expires_r ) );
88 ret +=
_(
"(EXPIRED)");
92 ret +=
_(
"(expires within 24h)");
96 ret +=
str::form(
PL_(
"(expires in %d day)",
"(expires in %d days)", ttl ), ttl );
119 static shared_ptr<Impl> _nullimpl(
new Impl );
124 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
127 {
return new Impl( *
this ); }
135 : _pimpl(
Impl::nullimpl() )
141 PublicSubkeyData::operator bool()
const
142 {
return !_pimpl->_id.empty(); }
184 if ( sub.id() == id_r )
197 static shared_ptr<Impl> _nullimpl(
new Impl );
202 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
205 {
return new Impl( *
this ); }
213 : _pimpl(
Impl::nullimpl() )
219 PublicKeyData::operator bool()
const
220 {
return !_pimpl->_fingerprint.empty(); }
257 str <<
", " << sub.id();
272 str <<
"[" << obj.
name() <<
"]" << endl;
274 str <<
" id " << obj.
id() << endl;
278 for (
auto && sub : obj.
_pimpl->_subkeys )
279 str <<
" sub " << sub << endl;
303 void scan( std::string & line_r, std::list<PublicKeyData> & keys_r )
313 if ( line_r.empty() )
321 if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
330 if ( line_r[1] ==
'p' && line_r[2] ==
'r' && line_r[3] ==
':' )
335 if ( line_r[1] ==
'i' && line_r[2] ==
'd' && line_r[3] ==
':' )
340 if ( line_r[1] ==
'i' && line_r[2] ==
'g' && line_r[3] ==
':' )
342 else if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
354 if ( line_r[line_r.size()-1] ==
'\n' )
355 line_r.erase( line_r.size()-1 );
375 Date cdate(str::strtonum<Date::ValueType>(
_words[5]));
387 if ( !
_words[9].empty() &&
_words[9] !=
"[User ID not found]" )
435 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.
size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
456 WAR <<
"Invalid PublicKeyData supplied: scanning from file" << endl;
487 "--no-default-keyring",
489 "--with-fingerprint",
506 scanner.
scan( line );
508 int ret = prog.
close();
510 switch ( scanner.
_keys.size() )
528 scanner.
_keys.pop_back();
545 static shared_ptr<Impl> _nullimpl(
new Impl );
550 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
553 {
return new Impl( *
this ); }
561 : _pimpl(
Impl::nullimpl() )
565 : _pimpl( new
Impl( file ) )
569 : _pimpl( new
Impl( sharedfile ) )
573 : _pimpl( new
Impl( sharedfile, keydata ) )
625 {
return sid ==
id(); }
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
#define PL_(MSG1, MSG2, N)
Exception thrown when the supplied key is not a valid gpg key.
Store and operate on date (time_t).
static const ValueType day
static Date now()
Return the current time.
std::string printDate(DateFormat dateFormat_r=DateFormat::calendar, TimeBase base_r=TB_LOCALTIME) const
Convenience for printing the date only ['2014-02-07'] The default is DateFormat::calendar and TB_LOCA...
Base class for Exception.
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
int close()
Wait for the progamm to complete.
Class representing one GPG Public Keys data.
Date created() const
Creation / last modification date (latest selfsig).
bool expired() const
Whether the key has expired.
std::string name() const
Key name.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
bool hasSubkeys() const
Whether subkeys is not empty.
PublicKeyData()
Default constructed: empty data.
Date expires() const
Expiry date, or Date() if the key never expires.
RWCOW_pointer< Impl > _pimpl
bool providesKey(const std::string &id_r) const
Whether id_r is the id of the primary key or of a subkey.
std::string id() const
Key ID.
std::string fingerprint() const
Key fingerprint.
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
std::string expiresAsString() const
std::string asString() const
Simple string representation.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Pathname path() const
File containig the ASCII armored key.
std::string expiresAsString() const
bool operator==(const PublicKey &rhs) const
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
const PublicKeyData & keyData() const
The public keys data (.
std::string gpgPubkeyRelease() const
std::string asString() const
std::string fingerprint() const
std::string gpgPubkeyVersion() const
Class representing a GPG Public Keys subkeys.
RWCOW_pointer< Impl > _pimpl
std::string id() const
Subkey ID.
PublicSubkeyData()
Default constructed: empty data.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Date expires() const
Expiry date, or Date() if the key never expires.
std::string asString() const
Simple string representation.
Date created() const
Creation date.
bool expired() const
Whether the key has expired.
std::string receiveLine()
Read one line from the input stream.
Wrapper class for ::stat/::lstat.
bool isExist() const
Return whether valid stat info exists.
const Pathname & path() const
Return current Pathname.
const std::string & asString() const
String representation.
Provide a new empty temporary file and delete it when no longer needed.
String related utilities and Regular expression matching.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
unsigned splitFields(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::string hexstring(char n, int w=4)
std::string toLower(const std::string &s)
Return lowercase version of s.
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...
Pathname myTmpDir()
Global access to the zypp.TMPDIR (created on demand, deleted when libzypp is unloaded)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
PublicKeyData implementation.
Impl * clone() const
clone for RWCOW_pointer
std::vector< PublicSubkeyData > _subkeys
static shared_ptr< Impl > nullimpl()
Offer default Impl.
bool hasSubkeyId(const std::string &id_r) const
PublicKeyScanner implementation.
void scan(std::string &line_r, std::list< PublicKeyData > &keys_r)
PublicKeyData::Impl * _keyDataPtr
std::vector< std::string > _words
enum zypp::PublicKeyScanner::Impl::@1 _parseEntry
Scan abstract from 'gpg –with-colons' key listings.
std::list< PublicKeyData > _keys
Extracted keys.
void scan(std::string line_r)
Feed gpg output line by line into scan.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
PublicKey implementation.
Impl(const Pathname &keyFile_r)
filesystem::TmpFile _dataFile
std::string _initHomeDir()
Impl * clone() const
clone for RWCOW_pointer
const std::list< PublicKeyData > & hiddenKeys() const
std::list< PublicKeyData > _hiddenKeys
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl(const filesystem::TmpFile &sharedFile_r)
Impl(const filesystem::TmpFile &sharedFile_r, const PublicKeyData &keyData_r)
const PublicKeyData & keyData() const
PublicSubkeyData implementation.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl * clone() const
clone for RWCOW_pointer
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...