Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / PublicKey.cc
index 80985bf..fc7435b 100644 (file)
@@ -28,6 +28,9 @@
 
 #include <ctime>
 
+/** \todo Fix duplicate define in PublicKey/KeyRing */
+#define GPG_BINARY "/usr/bin/gpg2"
+
 using std::endl;
 
 ///////////////////////////////////////////////////////////////////
@@ -99,7 +102,9 @@ namespace zypp
     if ( _pimpl->_expires )
     {
       Date exp( _pimpl->_expires - Date::now() );
-      return exp < 0 ? exp / Date::day - 1 : exp / Date::day;
+      int ret = exp / Date::day;
+      if ( exp < 0 ) ret -= 1;
+      return ret;
     }
     return INT_MAX;
   }
@@ -172,9 +177,11 @@ namespace zypp
   {
     std::vector<std::string>                   _words;
     enum { pNONE, pPUB, pSIG, pFPR, pUID }     _parseEntry;
+    bool                                       _parseOff;      // no 'sub:' key parsing
 
    Impl()
       : _parseEntry( pNONE )
+      , _parseOff( false )
     {}
 
     void scan( std::string & line_r, std::list<PublicKeyData> & keys_r )
@@ -190,18 +197,39 @@ namespace zypp
       if ( line_r.empty() )
        return;
 
-      // quick check for interesting entries
+      // quick check for interesting entries, no parsing in subkeys
       _parseEntry = pNONE;
       switch ( line_r[0] )
       {
-       #define DOTEST( C1, C2, C3, E ) case C1: if ( line_r[1] == C2 && line_r[2] == C3 && line_r[3] == ':' ) _parseEntry = E; break
-       DOTEST( 'p', 'u', 'b', pPUB );
-       DOTEST( 's', 'i', 'g', pSIG );
-       DOTEST( 'f', 'p', 'r', pFPR );
-       DOTEST( 'u', 'i', 'd', pUID );
-       #undef DOTEST
+       case 'p':
+         if ( line_r[1] == 'u' && line_r[2] == 'b' && line_r[3] == ':' )
+         {
+           _parseEntry = pPUB;
+           _parseOff = false;
+         }
+         break;
+
+       case 'f':
+         if ( line_r[1] == 'p' && line_r[2] == 'r' && line_r[3] == ':' )
+           _parseEntry = pFPR;
+         break;
+
+       case 'u':
+         if ( line_r[1] == 'i' && line_r[2] == 'd' && line_r[3] == ':' )
+           _parseEntry = pUID;
+         break;
+
+       case 's':
+         if ( line_r[1] == 'i' && line_r[2] == 'g' && line_r[3] == ':' )
+           _parseEntry = pSIG;
+         else if ( line_r[1] == 'u' && line_r[2] == 'b' && line_r[3] == ':' )
+           _parseOff = true;
+         break;
+
+       default:
+         return;
       }
-      if ( _parseEntry == pNONE )
+      if ( _parseOff || _parseEntry == pNONE )
        return;
 
       if ( line_r[line_r.size()-1] == '\n' )
@@ -226,7 +254,8 @@ namespace zypp
 
        case pSIG:
          // Update creation/modification date from signatures type "13x".
-         if ( _words[_words.size()-2] == "13x" )
+         if ( ( _words.size() > 10 && _words[10] == "13x" )
+           || ( _words.size() > 12 && _words[12] == "13x" ) )
          {
            Date cdate(str::strtonum<Date::ValueType>(_words[5]));
            if ( key->_pimpl->_created < cdate )
@@ -245,7 +274,7 @@ namespace zypp
          break;
 
        case pNONE:
-         break;
+         break;        // intentionally no default:
       }
     }
   };
@@ -323,7 +352,7 @@ namespace zypp
         static filesystem::TmpDir dir;
         const char* argv[] =
         {
-          "gpg",
+          GPG_BINARY,
           "-v",
           "--no-default-keyring",
           "--fixed-list-mode",
@@ -335,8 +364,7 @@ namespace zypp
           "--no-tty",
           "--no-greeting",
           "--batch",
-          "--status-fd",
-          "1",
+          "--status-fd", "1",
           _dataFile.path().asString().c_str(),
           NULL
         };