Provide additional keys data in case the ASCII armored blob containes multiple keys
authorMichael Andres <ma@suse.de>
Thu, 1 Aug 2013 17:37:23 +0000 (19:37 +0200)
committerMichael Andres <ma@suse.de>
Tue, 27 Aug 2013 16:44:36 +0000 (18:44 +0200)
zypp/PublicKey.cc
zypp/PublicKey.h

index 7fe3ba4..6996cd1 100644 (file)
@@ -311,6 +311,9 @@ namespace zypp
       Pathname path() const
       { return _dataFile.path(); }
 
+      const std::list<PublicKeyData> & hiddenKeys() const
+      { return _hiddenKeys; }
+
     protected:
       void readFromFile()
       {
@@ -354,20 +357,25 @@ namespace zypp
 
          case 1:
            // ok.
+           _keyData = scanner._keys.back();
+           _hiddenKeys.clear();
            break;
 
          default:
            WAR << "File " << _dataFile.path().asString() << " contains multiple keys: " <<  scanner._keys << endl;
+           _keyData = scanner._keys.back();
+           scanner._keys.pop_back();
+           _hiddenKeys.swap( scanner._keys );
            break;
        }
 
-       _keyData = scanner._keys.back();
        MIL << "Read pubkey from " << info.path() << ": " << _keyData << endl;
       }
 
     private:
       filesystem::TmpFile      _dataFile;
       PublicKeyData            _keyData;
+      std::list<PublicKeyData>  _hiddenKeys;
 
     public:
       /** Offer default Impl. */
@@ -413,6 +421,9 @@ namespace zypp
   Pathname PublicKey::path() const
   { return _pimpl->path(); }
 
+  const std::list<PublicKeyData> & PublicKey::hiddenKeys() const
+  { return _pimpl->hiddenKeys(); }
+
   std::string PublicKey::id() const
   { return keyData().id(); }
 
index 036f076..5f81d13 100644 (file)
@@ -197,8 +197,13 @@ namespace zypp
   ///////////////////////////////////////////////////////////////////
   /// \class PublicKey
   /// \brief Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
+  ///
   /// If you don't need the ASCII armored version of the key stored in
   /// a tempfile, using \ref PublicKeyData might be sufficient.
+  ///
+  /// \note In case the ASCII armored blob actually contains multiple
+  /// keys, the \b last keys data are made available via the API. The
+  /// additional keys data are made available via \ref hiddenKeys.
   ///////////////////////////////////////////////////////////////////
   class PublicKey
   {
@@ -249,11 +254,13 @@ namespace zypp
     std::string gpgPubkeyRelease() const;      //!< \see \ref PublicKeyData
     std::string asString() const;              //!< \see \ref PublicKeyData
 
-
   public:
     /** File containig the ASCII armored key. */
     Pathname path() const;
 
+    /** Additional keys data in case the ASCII armored blob containes multiple keys. */
+    const std::list<PublicKeyData> & hiddenKeys() const;
+
   public:
     bool operator==( PublicKey rhs ) const;    // FIXME: change arg to const&
     bool operator==( std::string sid ) const;  // FIXME: change arg to const&