Mailinglist Archive: zypp-commit (301 mails)

< Previous Next >
[zypp-commit] r7441 - in /trunk/libzypp/zypp: CheckSum.cc CheckSum.h sat/
  • From: mlandres@xxxxxxxxxxxxxxxx
  • Date: Thu, 04 Oct 2007 14:31:20 -0000
  • Message-id: <20071004143120.666A32FCED@xxxxxxxxxxxxxxxx>
Author: mlandres
Date: Thu Oct  4 16:31:19 2007
New Revision: 7441

URL: http://svn.opensuse.org/viewcvs/zypp?rev=7441&view=rev
Log:
throw constructing malformed checksums.

Added:
    trunk/libzypp/zypp/sat/
Modified:
    trunk/libzypp/zypp/CheckSum.cc
    trunk/libzypp/zypp/CheckSum.h

Modified: trunk/libzypp/zypp/CheckSum.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CheckSum.cc?rev=7441&r1=7440&r2=7441&view=diff
==============================================================================
--- trunk/libzypp/zypp/CheckSum.cc (original)
+++ trunk/libzypp/zypp/CheckSum.cc Thu Oct  4 16:31:19 2007
@@ -11,6 +11,7 @@
 */
 
 #include "zypp/base/Logger.h"
+#include "zypp/base/Gettext.h"
 #include "zypp/base/String.h"
 
 #include "zypp/CheckSum.h"
@@ -43,15 +44,15 @@
   , _checksum( checksum )
   {
     switch ( checksum.size() )
-      {
+    {
       case 64:
         if ( _type == sha256Type() )
           return;
         if ( _type.empty() || _type == shaType() )
-          {
-            _type = sha256Type();
-            return;
-          }
+        {
+          _type = sha256Type();
+          return;
+        }
         // else: dubious
         break;
 
@@ -59,10 +60,10 @@
         if ( _type == sha1Type() )
           return;
         if ( _type.empty() || _type == shaType() )
-          {
-            _type = sha1Type();
-            return;
-          }
+        {
+          _type = sha1Type();
+          return;
+        }
         // else: dubious
         break;
 
@@ -70,10 +71,10 @@
         if (  _type == md5Type() )
           return;
         if ( _type.empty() )
-          {
-            _type = md5Type();
-            return;
-          }
+        {
+          _type = md5Type();
+          return;
+        }
         // else: dubious
         break;
 
@@ -83,16 +84,28 @@
 
       default:
         if ( _type.empty() )
-          {
-            WAR << "Can't determine type of " << checksum.size() << " byte checksum '" << _checksum << "'" << endl;
-            return;
-          }
+        {
+          WAR << "Can't determine type of " << checksum.size() << " byte checksum '" << _checksum << "'" << endl;
+          return;
+        }
         // else: dubious
         break;
-      }
+    }
 
-    // dubious
-    WAR << "Dubious type '" << _type << "' for " << checksum.size() << " byte checksum '" << _checksum << "'" << endl;
+    // dubious: Throw on malformed known types, otherwise log a warning.
+    std::string msg = str::form ( _("Dubious type '%s' for %u byte checksum '%s'"),
+                                  _type.c_str(), checksum.size(), _checksum.c_str() );
+    if (    _type == md5Type()
+         || _type == shaType()
+         || _type == sha1Type()
+         || _type == sha256Type() )
+    {
+      ZYPP_THROW( CheckSumException( msg ) );
+    }
+    else
+    {
+      WAR << msg << endl;
+    }
   }
 
   CheckSum::CheckSum( const std::string & type_r, std::istream & input_r )
@@ -116,7 +129,7 @@
 
   bool CheckSum::empty() const
   { return (checksum().empty() || type().empty()); }
-  
+
   std::ostream & operator<<( std::ostream & str, const CheckSum & obj )
   {
     if ( obj.checksum().empty() )

Modified: trunk/libzypp/zypp/CheckSum.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CheckSum.h?rev=7441&r1=7440&r2=7441&view=diff
==============================================================================
--- trunk/libzypp/zypp/CheckSum.h (original)
+++ trunk/libzypp/zypp/CheckSum.h Thu Oct  4 16:31:19 2007
@@ -15,19 +15,26 @@
 #include <iosfwd>
 #include <string>
 
+#include "zypp/base/Exception.h"
 #include "zypp/Pathname.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
+  struct CheckSumException : public Exception
+  {
+    CheckSumException( const std::string & msg )
+      : Exception( msg )
+    {}
+  };
 
   class CheckSum
   {
   public:
     /**
      * Creates a checksum for algorithm \param type
-     * \throws if the checksum is invalid and can't be constructed
+     * \throws CheckSumException if the checksum is invalid and can't be constructed
      */
     CheckSum( const std::string & type, const std::string & checksum);
     CheckSum( const std::string & type, std::istream & input_r );

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages