libzypp  11.13.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  public:
53  static const std::string & md5Type();
54  static const std::string & shaType();
55  static const std::string & sha1Type();
56  static const std::string & sha256Type();
57 
58  static CheckSum md5( const std::string & checksum )
59  { return CheckSum( md5Type(), checksum); }
60  static CheckSum sha( const std::string & checksum )
61  { return CheckSum( shaType(), checksum); }
62  static CheckSum sha1( const std::string & checksum )
63  { return CheckSum( sha1Type(), checksum); }
64  static CheckSum sha256( const std::string & checksum )
65  { return CheckSum( sha256Type(), checksum); }
66 
67  static CheckSum md5( std::istream & input_r )
68  { return CheckSum( md5Type(), input_r ); }
69  static CheckSum sha( std::istream & input_r )
70  { return CheckSum( sha1Type(), input_r ); }
71  static CheckSum sha1( std::istream & input_r )
72  { return CheckSum( sha1Type(), input_r ); }
73  static CheckSum sha256( std::istream & input_r )
74  { return CheckSum( sha256Type(), input_r ); }
75 
76  public:
77  std::string type() const;
78  std::string checksum() const;
79  bool empty() const;
80 
81  public:
82  std::string asString() const;
83 
84  private:
85  std::string _type;
86  std::string _checksum;
87  };
88 
90  std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
91 
93  bool operator==( const CheckSum & lhs, const CheckSum & rhs );
94 
96  bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
97 
98 } // namespace zypp
100 #endif // ZYPP_CHECKSUM_H