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/Pathname.h"
00019 
00021 namespace zypp
00022 { 
00023 
00024 
00025   class CheckSum
00026   {
00027   public:
00028     CheckSum();
00029 
00030     CheckSum( const std::string & type, const std::string & checksum );
00031 
00032     CheckSum( const std::string & type, std::istream & input_r );
00033 
00034   public:
00035     static const std::string & md5Type();
00036     static const std::string & shaType();
00037     static const std::string & sha1Type();
00038     static const std::string & sha256Type();
00039 
00040     static CheckSum md5( const std::string & checksum )
00041     { return  CheckSum( md5Type(), checksum); }
00042     static CheckSum sha( const std::string & checksum )
00043     { return  CheckSum( shaType(), checksum); }
00044     static CheckSum sha1( const std::string & checksum )
00045     { return  CheckSum( sha1Type(), checksum); }
00046     static CheckSum sha256( const std::string & checksum )
00047     { return  CheckSum( sha256Type(), checksum); }
00048 
00049     static CheckSum md5( std::istream & input_r )
00050     { return  CheckSum( md5Type(), input_r ); }
00051     static CheckSum sha( std::istream & input_r )
00052     { return  CheckSum( sha1Type(), input_r ); }
00053     static CheckSum sha1( std::istream & input_r )
00054     { return  CheckSum( sha1Type(), input_r ); }
00055     static CheckSum sha256( std::istream & input_r )
00056     { return  CheckSum( sha256Type(), input_r ); }
00057 
00058   public:
00059     std::string type() const
00060     { return _type; }
00061 
00062     std::string checksum() const
00063     { return _checksum; }
00064 
00065     bool empty() const
00066     { return (checksum().empty() || type().empty()); }
00067 
00068   private:
00069     std::string _type;
00070     std::string _checksum;
00071   };
00072 
00074   std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
00075 
00077   inline bool operator==( const CheckSum & lhs, const CheckSum & rhs )
00078   { return lhs.checksum() == rhs.checksum() && lhs.type() == rhs.type(); }
00079 
00081   inline bool operator!=( const CheckSum & lhs, const CheckSum & rhs )
00082   { return ! ( lhs == rhs ); }
00083 
00084 } // namespace zypp
00086 #endif // ZYPP_CHECKSUM_H

Generated on Wed Sep 27 01:16:30 2006 for zypp by  doxygen 1.4.6