- Create the cache directly from the schema (installed) file.
[platform/upstream/libzypp.git] / zypp / CheckSum.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/CheckSum.h
10  *
11 */
12 #ifndef ZYPP_CHECKSUM_H
13 #define ZYPP_CHECKSUM_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include "zypp/Pathname.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24
25   class CheckSum
26   {
27   public:
28     /**
29      * Creates a checksum for algorithm \param type
30      * \throws if the checksum is invalid and can't be constructed
31      */
32     CheckSum( const std::string & type, const std::string & checksum);
33     CheckSum( const std::string & type, std::istream & input_r );
34     CheckSum();
35
36   public:
37     static const std::string & md5Type();
38     static const std::string & shaType();
39     static const std::string & sha1Type();
40     static const std::string & sha256Type();
41
42     static CheckSum md5( const std::string & checksum )
43     { return  CheckSum( md5Type(), checksum); }
44     static CheckSum sha( const std::string & checksum )
45     { return  CheckSum( shaType(), checksum); }
46     static CheckSum sha1( const std::string & checksum )
47     { return  CheckSum( sha1Type(), checksum); }
48     static CheckSum sha256( const std::string & checksum )
49     { return  CheckSum( sha256Type(), checksum); }
50
51     static CheckSum md5( std::istream & input_r )
52     { return  CheckSum( md5Type(), input_r ); }
53     static CheckSum sha( std::istream & input_r )
54     { return  CheckSum( sha1Type(), input_r ); }
55     static CheckSum sha1( std::istream & input_r )
56     { return  CheckSum( sha1Type(), input_r ); }
57     static CheckSum sha256( std::istream & input_r )
58     { return  CheckSum( sha256Type(), input_r ); }
59
60   public:
61     std::string type() const;
62     std::string checksum() const;
63     bool empty() const;
64
65   private:
66     std::string _type;
67     std::string _checksum;
68   };
69
70   /** \relates CheckSum Stream output. */
71   std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
72
73   /** \relates CheckSum */
74   bool operator==( const CheckSum & lhs, const CheckSum & rhs );
75
76   /** \relates CheckSum */
77   bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
78
79 } // namespace zypp
80 ///////////////////////////////////////////////////////////////////
81 #endif // ZYPP_CHECKSUM_H