libzypp  13.10.6
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  std::ostream & dumpAsXmlOn( std::ostream & str, const CheckSum & obj );
101 
103  bool operator==( const CheckSum & lhs, const CheckSum & rhs );
104 
106  bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
107 
108 } // namespace zypp
110 #endif // ZYPP_CHECKSUM_H
static CheckSum sha(const std::string &checksum)
Definition: CheckSum.h:67
bool empty() const
Definition: CheckSum.cc:137
bool operator!=(const CountryCode &lhs, const CountryCode &rhs)
const std::string & msg() const
Return the message string provided to the ctor.
Definition: Exception.h:185
std::ostream & dumpAsXmlOn(std::ostream &str, const CheckSum &obj)
Definition: CheckSum.cc:157
static const std::string & shaType()
Definition: CheckSum.cc:31
CheckSumException(const std::string &msg)
Definition: CheckSum.h:27
std::string _checksum
Definition: CheckSum.h:93
static CheckSum md5(const std::string &checksum)
Definition: CheckSum.h:65
std::string asString() const
Definition: CheckSum.cc:140
static CheckSum sha1(std::istream &input_r)
Definition: CheckSum.h:78
std::string _type
Definition: CheckSum.h:92
static const std::string & sha256Type()
Definition: CheckSum.cc:37
static CheckSum md5(std::istream &input_r)
Definition: CheckSum.h:74
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
std::string checksum() const
Definition: CheckSum.cc:134
static CheckSum sha(std::istream &input_r)
Definition: CheckSum.h:76
std::string type() const
Definition: CheckSum.cc:131
static CheckSum sha256(const std::string &checksum)
Definition: CheckSum.h:71
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:309
static CheckSum sha256(std::istream &input_r)
Definition: CheckSum.h:80
Base class for Exception.
Definition: Exception.h:143
static const std::string & sha1Type()
Definition: CheckSum.cc:34
CheckSum()
Default Ctor: empty checksum.
Definition: CheckSum.cc:41
static CheckSum sha1(const std::string &checksum)
Definition: CheckSum.h:69
static const std::string & md5Type()
Definition: CheckSum.cc:28
CheckSum(const std::string &type, std::istream &&input_r)
Move Ctor.
Definition: CheckSum.h:54