*/
#include "zypp/base/Logger.h"
+#include "zypp/base/Gettext.h"
#include "zypp/base/String.h"
#include "zypp/CheckSum.h"
, _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;
if ( _type == sha1Type() )
return;
if ( _type.empty() || _type == shaType() )
- {
- _type = sha1Type();
- return;
- }
+ {
+ _type = sha1Type();
+ return;
+ }
// else: dubious
break;
if ( _type == md5Type() )
return;
if ( _type.empty() )
- {
- _type = md5Type();
- return;
- }
+ {
+ _type = md5Type();
+ return;
+ }
// else: dubious
break;
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 )
bool CheckSum::empty() const
{ return (checksum().empty() || type().empty()); }
-
+
std::ostream & operator<<( std::ostream & str, const CheckSum & obj )
{
if ( obj.checksum().empty() )
#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 );