1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/CheckSum.h
12 #ifndef ZYPP_CHECKSUM_H
13 #define ZYPP_CHECKSUM_H
18 #include "zypp/base/Exception.h"
19 #include "zypp/Pathname.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 struct CheckSumException : public Exception
27 CheckSumException( const std::string & msg )
35 /** Default Ctor: empty checksum. */
38 * Creates a checksum auto probing the algorithm type.
39 * \throws CheckSumException if the checksum is invalid and can't be constructed
41 CheckSum( const std::string & checksum );
43 * Creates a checksum for algorithm \param type.
44 * \throws CheckSumException if the checksum is invalid and can't be constructed
46 CheckSum( const std::string & type, const std::string & checksum );
48 * Reads the content of \param input_r and computes the checksum.
50 CheckSum( const std::string & type, std::istream & input_r );
52 #ifndef SWIG // Swig treats it as syntax error
54 CheckSum( const std::string & type, std::istream && input_r )
55 : CheckSum( type, input_r )
60 static const std::string & md5Type();
61 static const std::string & shaType();
62 static const std::string & sha1Type();
63 static const std::string & sha256Type();
65 static CheckSum md5( const std::string & checksum )
66 { return CheckSum( md5Type(), checksum); }
67 static CheckSum sha( const std::string & checksum )
68 { return CheckSum( shaType(), checksum); }
69 static CheckSum sha1( const std::string & checksum )
70 { return CheckSum( sha1Type(), checksum); }
71 static CheckSum sha256( const std::string & checksum )
72 { return CheckSum( sha256Type(), checksum); }
74 static CheckSum md5( std::istream & input_r )
75 { return CheckSum( md5Type(), input_r ); }
76 static CheckSum sha( std::istream & input_r )
77 { return CheckSum( sha1Type(), input_r ); }
78 static CheckSum sha1( std::istream & input_r )
79 { return CheckSum( sha1Type(), input_r ); }
80 static CheckSum sha256( std::istream & input_r )
81 { return CheckSum( sha256Type(), input_r ); }
84 std::string type() const;
85 std::string checksum() const;
89 std::string asString() const;
93 std::string _checksum;
96 /** \relates CheckSum Stream output. */
97 std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
99 /** \relates CheckSum */
100 bool operator==( const CheckSum & lhs, const CheckSum & rhs );
102 /** \relates CheckSum */
103 bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
106 ///////////////////////////////////////////////////////////////////
107 #endif // ZYPP_CHECKSUM_H