libzypp
10.5.0
|
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: 00039 CheckSum( const std::string & type, const std::string & checksum ); 00040 CheckSum( const std::string & type, std::istream & input_r ); 00041 CheckSum(); 00042 00043 public: 00044 static const std::string & md5Type(); 00045 static const std::string & shaType(); 00046 static const std::string & sha1Type(); 00047 static const std::string & sha256Type(); 00048 00049 static CheckSum md5( const std::string & checksum ) 00050 { return CheckSum( md5Type(), checksum); } 00051 static CheckSum sha( const std::string & checksum ) 00052 { return CheckSum( shaType(), checksum); } 00053 static CheckSum sha1( const std::string & checksum ) 00054 { return CheckSum( sha1Type(), checksum); } 00055 static CheckSum sha256( const std::string & checksum ) 00056 { return CheckSum( sha256Type(), checksum); } 00057 00058 static CheckSum md5( std::istream & input_r ) 00059 { return CheckSum( md5Type(), input_r ); } 00060 static CheckSum sha( std::istream & input_r ) 00061 { return CheckSum( sha1Type(), input_r ); } 00062 static CheckSum sha1( std::istream & input_r ) 00063 { return CheckSum( sha1Type(), input_r ); } 00064 static CheckSum sha256( std::istream & input_r ) 00065 { return CheckSum( sha256Type(), input_r ); } 00066 00067 public: 00068 std::string type() const; 00069 std::string checksum() const; 00070 bool empty() const; 00071 00072 public: 00073 std::string asString() const; 00074 00075 private: 00076 std::string _type; 00077 std::string _checksum; 00078 }; 00079 00081 std::ostream & operator<<( std::ostream & str, const CheckSum & obj ); 00082 00084 bool operator==( const CheckSum & lhs, const CheckSum & rhs ); 00085 00087 bool operator!=( const CheckSum & lhs, const CheckSum & rhs ); 00088 00089 } // namespace zypp 00091 #endif // ZYPP_CHECKSUM_H