CheckSum.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_CHECKSUM_H
00013 #define ZYPP_CHECKSUM_H
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 
00018 #include "zypp/base/String.h"
00019 
00021 namespace zypp
00022 { 
00023 
00024   class CheckSum
00025   {
00026   public:
00027     CheckSum(const std::string & type, const std::string & checksum)
00028     {
00029       _checksum = checksum;
00030       if (str::toLower(type) == "sha")
00031       {
00032         if (checksum.size() == 40)
00033           _type = "sha1";
00034         else if (checksum.size() == 64)
00035           _type = "sha256";
00036       }
00037       else
00038       {
00039         _type = type;
00040       }
00041     }
00042 
00043     CheckSum()
00044     {}
00045 
00046     std::string type() const
00047     { return _type; }
00048     std::string checksum() const
00049     { return _checksum; }
00050 
00051     bool empty() const
00052     { return (checksum().empty() || type().empty()); }
00053   private:
00054     std::string _type;
00055     std::string _checksum;
00056   };
00057 
00059   inline std::ostream & operator<<( std::ostream & str, const CheckSum & obj )
00060   { return str << (obj.empty() ? std::string("NoCheckSum")
00061                                : obj.type()+"-"+obj.checksum()  ); }
00062 
00064   inline bool operator==( const CheckSum & lhs, const CheckSum & rhs )
00065   { return lhs.checksum() == rhs.checksum() && lhs.type() == rhs.type(); }
00066 
00068   inline bool operator!=( const CheckSum & lhs, const CheckSum & rhs )
00069   { return ! ( lhs == rhs ); }
00070 
00071 } // namespace zypp
00073 #endif // ZYPP_CHECKSUM_H

Generated on Thu Jul 6 00:07:20 2006 for zypp by  doxygen 1.4.6