libzypp  17.14.0
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 #include <sstream>
18 
19 #include "zypp/base/Exception.h"
20 #include "zypp/Pathname.h"
21 
23 namespace zypp
24 {
25 
26  struct CheckSumException : public Exception
27  {
28  CheckSumException( const std::string & msg )
29  : Exception( msg )
30  {}
31  };
32 
33  class CheckSum
34  {
35  public:
38  {}
43  CheckSum( const std::string & type, const std::string & checksum );
48  CheckSum( const std::string & checksum )
49  : CheckSum( std::string(), checksum )
50  {}
51 
55  CheckSum( const std::string & type, std::istream & input_r );
56 
57 #ifndef SWIG // Swig treats it as syntax error0
58 
59  CheckSum( const std::string & type, std::istream && input_r )
60  : CheckSum( type, input_r )
61  {}
62 #endif
63 
64  public:
65  static const std::string & md5Type();
66  static const std::string & shaType();
67  static const std::string & sha1Type();
68  static const std::string & sha224Type();
69  static const std::string & sha256Type();
70  static const std::string & sha384Type();
71  static const std::string & sha512Type();
72 
75  static CheckSum md5( const std::string & checksum ) { return CheckSum( md5Type(), checksum); }
76  static CheckSum sha( const std::string & checksum ) { return CheckSum( shaType(), checksum); }
77  static CheckSum sha1( const std::string & checksum ) { return CheckSum( sha1Type(), checksum); }
78  static CheckSum sha224( const std::string & checksum ) { return CheckSum( sha224Type(), checksum); }
79  static CheckSum sha256( const std::string & checksum ) { return CheckSum( sha256Type(), checksum); }
80  static CheckSum sha384( const std::string & checksum ) { return CheckSum( sha384Type(), checksum); }
81  static CheckSum sha512( const std::string & checksum ) { return CheckSum( sha512Type(), checksum); }
83 
86  static CheckSum md5( std::istream & input_r ) { return CheckSum( md5Type(), input_r ); }
87  static CheckSum sha( std::istream & input_r ) { return CheckSum( sha1Type(), input_r ); }
88  static CheckSum sha1( std::istream & input_r ) { return CheckSum( sha1Type(), input_r ); }
89  static CheckSum sha224( std::istream & input_r ) { return CheckSum( sha224Type(), input_r ); }
90  static CheckSum sha256( std::istream & input_r ) { return CheckSum( sha256Type(), input_r ); }
91  static CheckSum sha384( std::istream & input_r ) { return CheckSum( sha384Type(), input_r ); }
92  static CheckSum sha512( std::istream & input_r ) { return CheckSum( sha512Type(), input_r ); }
93 #ifndef SWIG // Swig treats it as syntax error
94  static CheckSum md5( std::istream && input_r ) { return CheckSum( md5Type(), input_r ); }
95  static CheckSum sha( std::istream && input_r ) { return CheckSum( sha1Type(), input_r ); }
96  static CheckSum sha1( std::istream && input_r ) { return CheckSum( sha1Type(), input_r ); }
97  static CheckSum sha224( std::istream && input_r ) { return CheckSum( sha224Type(), input_r ); }
98  static CheckSum sha256( std::istream && input_r ) { return CheckSum( sha256Type(), input_r ); }
99  static CheckSum sha384( std::istream && input_r ) { return CheckSum( sha384Type(), input_r ); }
100  static CheckSum sha512( std::istream && input_r ) { return CheckSum( sha512Type(), input_r ); }
101 #endif
102 
103 
106  static CheckSum md5FromString( const std::string & input_r ) { return md5( std::stringstream( input_r ) ); }
107  static CheckSum shaFromString( const std::string & input_r ) { return sha( std::stringstream( input_r ) ); }
108  static CheckSum sha1FromString( const std::string & input_r ) { return sha1( std::stringstream( input_r ) ); }
109  static CheckSum sha224FromString( const std::string & input_r ) { return sha224( std::stringstream( input_r ) ); }
110  static CheckSum sha256FromString( const std::string & input_r ) { return sha256( std::stringstream( input_r ) ); }
111  static CheckSum sha384FromString( const std::string & input_r ) { return sha384( std::stringstream( input_r ) ); }
112  static CheckSum sha512FromString( const std::string & input_r ) { return sha512( std::stringstream( input_r ) ); }
114 
115  public:
116  std::string type() const;
117  std::string checksum() const;
118  bool empty() const;
119 
120  public:
121  std::string asString() const;
122 
123  private:
124  std::string _type;
125  std::string _checksum;
126  };
127 
129  std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
130 
132  std::ostream & dumpAsXmlOn( std::ostream & str, const CheckSum & obj );
133 
135  bool operator==( const CheckSum & lhs, const CheckSum & rhs );
136 
138  bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
139 
140 } // namespace zypp
142 #endif // ZYPP_CHECKSUM_H
static CheckSum sha224FromString(const std::string &input_r)
Definition: CheckSum.h:109
static CheckSum sha224(std::istream &&input_r)
Definition: CheckSum.h:97
static CheckSum sha(const std::string &checksum)
Definition: CheckSum.h:76
static const std::string & sha224Type()
Definition: CheckSum.cc:37
CheckSum(const std::string &checksum)
Creates a checksum auto probing the algorithm type.
Definition: CheckSum.h:48
static CheckSum shaFromString(const std::string &input_r)
Definition: CheckSum.h:107
std::string asString() const
Definition: CheckSum.cc:176
std::string checksum() const
Definition: CheckSum.cc:170
static const std::string & shaType()
Definition: CheckSum.cc:31
String related utilities and Regular expression matching.
Definition: Arch.h:344
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
static CheckSum sha512FromString(const std::string &input_r)
Definition: CheckSum.h:112
CheckSumException(const std::string &msg)
Definition: CheckSum.h:28
std::string _checksum
Definition: CheckSum.h:125
static CheckSum md5(const std::string &checksum)
Definition: CheckSum.h:75
static CheckSum sha1(std::istream &input_r)
Definition: CheckSum.h:88
static CheckSum sha256(std::istream &&input_r)
Definition: CheckSum.h:98
static CheckSum md5FromString(const std::string &input_r)
Definition: CheckSum.h:106
std::string _type
Definition: CheckSum.h:124
static CheckSum sha384(std::istream &input_r)
Definition: CheckSum.h:91
static const std::string & sha256Type()
Definition: CheckSum.cc:40
static const std::string & sha512Type()
Definition: CheckSum.cc:46
static CheckSum md5(std::istream &input_r)
Definition: CheckSum.h:86
static CheckSum sha256FromString(const std::string &input_r)
Definition: CheckSum.h:110
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
static CheckSum sha224(const std::string &checksum)
Definition: CheckSum.h:78
static CheckSum sha512(std::istream &input_r)
Definition: CheckSum.h:92
std::string type() const
Definition: CheckSum.cc:167
static CheckSum sha(std::istream &input_r)
Definition: CheckSum.h:87
static CheckSum sha256(const std::string &checksum)
Definition: CheckSum.h:79
static CheckSum sha256(std::istream &input_r)
Definition: CheckSum.h:90
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
static CheckSum sha384FromString(const std::string &input_r)
Definition: CheckSum.h:111
static const std::string & sha384Type()
Definition: CheckSum.cc:43
static CheckSum sha(std::istream &&input_r)
Definition: CheckSum.h:95
static CheckSum sha384(std::istream &&input_r)
Definition: CheckSum.h:99
Base class for Exception.
Definition: Exception.h:145
bool empty() const
Definition: CheckSum.cc:173
static const std::string & sha1Type()
Definition: CheckSum.cc:34
static CheckSum sha224(std::istream &input_r)
Definition: CheckSum.h:89
static CheckSum sha1(std::istream &&input_r)
Definition: CheckSum.h:96
static CheckSum sha384(const std::string &checksum)
Definition: CheckSum.h:80
static CheckSum md5(std::istream &&input_r)
Definition: CheckSum.h:94
CheckSum()
Default Ctor: empty checksum.
Definition: CheckSum.h:37
static CheckSum sha512(std::istream &&input_r)
Definition: CheckSum.h:100
static CheckSum sha1(const std::string &checksum)
Definition: CheckSum.h:77
static const std::string & md5Type()
Definition: CheckSum.cc:28
static CheckSum sha512(const std::string &checksum)
Definition: CheckSum.h:81
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
static CheckSum sha1FromString(const std::string &input_r)
Definition: CheckSum.h:108
std::ostream & dumpAsXmlOn(std::ostream &str, const Tp &obj, const std::string &name_r)
Definition: Xml.h:213
CheckSum(const std::string &type, std::istream &&input_r)
Ctor from temporary istream.
Definition: CheckSum.h:59
const std::string & msg() const
Return the message string provided to the ctor.
Definition: Exception.h:195