53 static shared_ptr<Impl> _nullimpl(
new Impl );
58 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
61 {
return new Impl( *
this ); }
70 : _pimpl(
Impl::nullimpl() )
76 PublicKeyData::operator bool()
const
77 {
return !_pimpl->_fingerprint.empty(); }
86 {
return _pimpl->_fingerprint; }
89 {
return _pimpl->_created; }
92 {
return _pimpl->_expires; }
111 return _(
"(does not expire)");
113 std::string ret(
_pimpl->_expires.asString() );
120 ret +=
_(
"(EXPIRED)");
124 ret +=
_(
"(expires within 24h)");
128 ret +=
str::form(
_PL(
"(expires in %d day)",
"(expires in %d days)", ttl ), ttl );
142 return str::form(
"[%s-%s] [%s] [%s] [TTL %d]",
146 _pimpl->_fingerprint.c_str(),
152 str <<
"[" << obj.
name() <<
"]" << endl;
154 str <<
" id " << obj.
id() << endl;
182 void scan( std::string & line_r, std::list<PublicKeyData> & keys_r )
192 if ( line_r.empty() )
200 if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
208 if ( line_r[1] ==
'p' && line_r[2] ==
'r' && line_r[3] ==
':' )
213 if ( line_r[1] ==
'i' && line_r[2] ==
'd' && line_r[3] ==
':' )
218 if ( line_r[1] ==
'i' && line_r[2] ==
'g' && line_r[3] ==
':' )
220 else if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
230 if ( line_r[line_r.size()-1] ==
'\n' )
231 line_r.erase( line_r.size()-1 );
243 key = &keys_r.back();
244 key->_pimpl->_id =
_words[4];
246 key->_pimpl->_created =
Date(str::strtonum<Date::ValueType>(
_words[5]));
247 key->_pimpl->_expires =
Date(str::strtonum<Date::ValueType>(
_words[6]));
255 Date cdate(str::strtonum<Date::ValueType>(
_words[5]));
256 if ( key->_pimpl->_created < cdate )
257 key->_pimpl->_created = cdate;
262 if ( key->_pimpl->_fingerprint.empty() )
263 key->_pimpl->_fingerprint =
_words[9];
267 if ( !
_words[9].empty() )
302 Impl(
const Pathname & keyFile_r )
304 PathInfo info( keyFile_r );
305 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
307 if ( !info.isExist() )
308 ZYPP_THROW(
Exception(
"Can't read public key from " + keyFile_r.asString() +
", file not found"));
326 WAR <<
"Invalid PublicKeyData supplied: scanning from file" << endl;
345 MIL <<
"Reading pubkey from " << info.path() <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(info.path(),
"sha1") << endl;
352 "--no-default-keyring",
354 "--with-fingerprint",
371 scanner.
scan( line );
375 switch ( scanner.
_keys.size() )
390 scanner.
_keys.pop_back();
395 MIL <<
"Read pubkey from " << info.path() <<
": " <<
_keyData << endl;
407 static shared_ptr<Impl> _nullimpl(
new Impl );
412 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
415 {
return new Impl( *
this ); }
423 : _pimpl(
Impl::nullimpl() )
427 : _pimpl( new
Impl( file ) )
431 : _pimpl( new
Impl( sharedfile ) )
435 : _pimpl( new
Impl( sharedfile, keydata ) )
442 {
return _pimpl->keyData(); }
445 {
return _pimpl->path(); }
448 {
return _pimpl->hiddenKeys(); }
487 {
return sid ==
id(); }
std::string name() const
Key name.
static const ValueType day
Date expires() const
Expiry date, or Date() if the key never expires.
Impl(const filesystem::TmpFile &sharedFile_r, const PublicKeyData &keyData_r)
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
enum zypp::PublicKeyScanner::Impl::@1 _parseEntry
std::list< PublicKeyData > _hiddenKeys
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
std::list< PublicKeyData > _keys
Extracted keys.
Impl * clone() const
clone for RWCOW_pointer
#define _PL(MSG1, MSG2, N)
Return translated text (plural form).
Class representing one GPG Public Keys data.
const std::string & asString() const
String representation.
Exception thrown when the supplied key is not a valid gpg key.
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
std::string asString() const
void scan(std::string line_r)
Feed gpg output line by line into scan.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
PublicKeyScanner implementation.
std::string expiresAsString() const
Provide a new empty temporary file and delete it when no longer needed.
const std::list< PublicKeyData > & hiddenKeys() const
PublicKeyData()
Default constructed: empty data.
std::string gpgPubkeyVersion() const
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).
Pathname path() const
File containig the ASCII armored key.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Store and operate on date (time_t).
Provide a new empty temporary directory and recursively delete it when no longer needed.
Impl(const Pathname &keyFile_r)
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
std::string fingerprint() const
Key fingerprint.
std::string expiresAsString() const
bool expired() const
Whether the key has expired.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
#define _(MSG)
Return translated text.
std::string receiveLine()
Read one line from the input stream.
Scan abstract from 'gpg –with-colons' key listings.
std::string toLower(const std::string &s)
Return lowercase version of s.
std::vector< std::string > _words
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
PublicKey implementation.
int close()
Wait for the progamm to complete.
std::string form(const char *format,...)
Printf style construction of std::string.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Base class for Exception.
Impl(const filesystem::TmpFile &sharedFile_r)
const PublicKeyData & keyData() const
The public keys data (.
static Date now()
Return the current time.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
RWCOW_pointer< Impl > _pimpl
Impl * clone() const
clone for RWCOW_pointer
std::string id() const
Key ID.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
void scan(std::string &line_r, std::list< PublicKeyData > &keys_r)
PublicKeyData implementation.
std::string fingerprint() const
filesystem::TmpFile _dataFile
Date created() const
Creation / last modification date (latest selfsig).
std::string gpgPubkeyRelease() const
std::string hexstring(char n, int w=4)
bool operator==(const PublicKey &rhs) const
std::string asString() const
Simple string representation.
const PublicKeyData & keyData() const
unsigned splitFields(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields.