libzypp 9.41.1

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/Exception.h"
00019 #include "zypp/Pathname.h"
00020 
00022 namespace zypp
00023 { 
00024 
00025   struct CheckSumException : public Exception
00026   {
00027     CheckSumException( const std::string & msg )
00028       : Exception( msg )
00029     {}
00030   };
00031 
00032   class CheckSum
00033   {
00034   public:
00036     CheckSum();
00041     CheckSum( const std::string & checksum );
00046     CheckSum( const std::string & type, const std::string & checksum );
00050     CheckSum( const std::string & type, std::istream & input_r );
00051 
00052   public:
00053     static const std::string & md5Type();
00054     static const std::string & shaType();
00055     static const std::string & sha1Type();
00056     static const std::string & sha256Type();
00057 
00058     static CheckSum md5( const std::string & checksum )
00059     { return  CheckSum( md5Type(), checksum); }
00060     static CheckSum sha( const std::string & checksum )
00061     { return  CheckSum( shaType(), checksum); }
00062     static CheckSum sha1( const std::string & checksum )
00063     { return  CheckSum( sha1Type(), checksum); }
00064     static CheckSum sha256( const std::string & checksum )
00065     { return  CheckSum( sha256Type(), checksum); }
00066 
00067     static CheckSum md5( std::istream & input_r )
00068     { return  CheckSum( md5Type(), input_r ); }
00069     static CheckSum sha( std::istream & input_r )
00070     { return  CheckSum( sha1Type(), input_r ); }
00071     static CheckSum sha1( std::istream & input_r )
00072     { return  CheckSum( sha1Type(), input_r ); }
00073     static CheckSum sha256( std::istream & input_r )
00074     { return  CheckSum( sha256Type(), input_r ); }
00075 
00076   public:
00077     std::string type() const;
00078     std::string checksum() const;
00079     bool empty() const;
00080 
00081   public:
00082     std::string asString() const;
00083 
00084   private:
00085     std::string _type;
00086     std::string _checksum;
00087   };
00088 
00090   std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
00091 
00093   bool operator==( const CheckSum & lhs, const CheckSum & rhs );
00094 
00096   bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
00097 
00098 } // namespace zypp
00100 #endif // ZYPP_CHECKSUM_H