libzypp  12.16.5
CheckSum.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_CHECKSUM_H
13 #define ZYPP_CHECKSUM_H
14 
15 #include <iosfwd>
16 #include <string>
17 
18 #include "zypp/base/Exception.h"
19 #include "zypp/Pathname.h"
20 
22 namespace zypp
23 {
24 
25  struct CheckSumException : public Exception
26  {
27  CheckSumException( const std::string & msg )
28  : Exception( msg )
29  {}
30  };
31 
32  class CheckSum
33  {
34  public:
36  CheckSum();
41  CheckSum( const std::string & checksum );
46  CheckSum( const std::string & type, const std::string & checksum );
50  CheckSum( const std::string & type, std::istream & input_r );
51 
52 #ifndef SWIG // Swig treats it as syntax error
53 
54  CheckSum( const std::string & type, std::istream && input_r )
55  : CheckSum( type, input_r )
56  {}
57 #endif
58 
59  public:
60  static const std::string & md5Type();
61  static const std::string & shaType();
62  static const std::string & sha1Type();
63  static const std::string & sha256Type();
64 
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); }
73 
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 ); }
82 
83  public:
84  std::string type() const;
85  std::string checksum() const;
86  bool empty() const;
87 
88  public:
89  std::string asString() const;
90 
91  private:
92  std::string _type;
93  std::string _checksum;
94  };
95 
97  std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
98 
100  bool operator==( const CheckSum & lhs, const CheckSum & rhs );
101 
103  bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
104 
105 } // namespace zypp
107 #endif // ZYPP_CHECKSUM_H