libzypp  17.28.8
CheckSum.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_CORE_CHECKSUM_H
13 #define ZYPP_CORE_CHECKSUM_H
14 
15 #include <iosfwd>
16 #include <string>
17 #include <sstream>
18 
19 #include <zypp-core/base/Exception.h>
20 #include <zypp-core/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 
58  CheckSum( const std::string & type, std::istream && input_r )
59  : CheckSum( type, input_r )
60  {}
61 
62  public:
63  static const std::string & md5Type();
64  static const std::string & shaType();
65  static const std::string & sha1Type();
66  static const std::string & sha224Type();
67  static const std::string & sha256Type();
68  static const std::string & sha384Type();
69  static const std::string & sha512Type();
70 
73  static CheckSum md5( const std::string & checksum ) { return CheckSum( md5Type(), checksum); }
74  static CheckSum sha( const std::string & checksum ) { return CheckSum( shaType(), checksum); }
75  static CheckSum sha1( const std::string & checksum ) { return CheckSum( sha1Type(), checksum); }
76  static CheckSum sha224( const std::string & checksum ) { return CheckSum( sha224Type(), checksum); }
77  static CheckSum sha256( const std::string & checksum ) { return CheckSum( sha256Type(), checksum); }
78  static CheckSum sha384( const std::string & checksum ) { return CheckSum( sha384Type(), checksum); }
79  static CheckSum sha512( const std::string & checksum ) { return CheckSum( sha512Type(), checksum); }
81 
84  static CheckSum md5( std::istream & input_r ) { return CheckSum( md5Type(), input_r ); }
85  static CheckSum sha( std::istream & input_r ) { return CheckSum( sha1Type(), input_r ); }
86  static CheckSum sha1( std::istream & input_r ) { return CheckSum( sha1Type(), input_r ); }
87  static CheckSum sha224( std::istream & input_r ) { return CheckSum( sha224Type(), input_r ); }
88  static CheckSum sha256( std::istream & input_r ) { return CheckSum( sha256Type(), input_r ); }
89  static CheckSum sha384( std::istream & input_r ) { return CheckSum( sha384Type(), input_r ); }
90  static CheckSum sha512( std::istream & input_r ) { return CheckSum( sha512Type(), input_r ); }
91 
92  static CheckSum md5( std::istream && input_r ) { return CheckSum( md5Type(), input_r ); }
93  static CheckSum sha( std::istream && input_r ) { return CheckSum( sha1Type(), input_r ); }
94  static CheckSum sha1( std::istream && input_r ) { return CheckSum( sha1Type(), input_r ); }
95  static CheckSum sha224( std::istream && input_r ) { return CheckSum( sha224Type(), input_r ); }
96  static CheckSum sha256( std::istream && input_r ) { return CheckSum( sha256Type(), input_r ); }
97  static CheckSum sha384( std::istream && input_r ) { return CheckSum( sha384Type(), input_r ); }
98  static CheckSum sha512( std::istream && input_r ) { return CheckSum( sha512Type(), input_r ); }
100 
103  static CheckSum md5FromString( const std::string & input_r ) { return md5( std::stringstream( input_r ) ); }
104  static CheckSum shaFromString( const std::string & input_r ) { return sha( std::stringstream( input_r ) ); }
105  static CheckSum sha1FromString( const std::string & input_r ) { return sha1( std::stringstream( input_r ) ); }
106  static CheckSum sha224FromString( const std::string & input_r ) { return sha224( std::stringstream( input_r ) ); }
107  static CheckSum sha256FromString( const std::string & input_r ) { return sha256( std::stringstream( input_r ) ); }
108  static CheckSum sha384FromString( const std::string & input_r ) { return sha384( std::stringstream( input_r ) ); }
109  static CheckSum sha512FromString( const std::string & input_r ) { return sha512( std::stringstream( input_r ) ); }
111 
112  public:
113  std::string type() const;
114  std::string checksum() const;
115  bool empty() const;
116 
117  public:
118  std::string asString() const;
119 
120  private:
121  std::string _type;
122  std::string _checksum;
123  };
124 
126  std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
127 
129  std::ostream & dumpAsXmlOn( std::ostream & str, const CheckSum & obj );
130 
132  bool operator==( const CheckSum & lhs, const CheckSum & rhs );
133 
135  bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
136 
137 } // namespace zypp
139 #endif // ZYPP_CHECKSUM_H
static CheckSum md5(std::istream &&input_r)
Definition: CheckSum.h:92
static CheckSum sha224FromString(const std::string &input_r)
Definition: CheckSum.h:106
static CheckSum sha512(std::istream &&input_r)
Definition: CheckSum.h:98
static CheckSum sha1FromString(const std::string &input_r)
Definition: CheckSum.h:105
static CheckSum md5(const std::string &checksum)
Definition: CheckSum.h:73
CheckSum(const std::string &checksum)
Creates a checksum auto probing the algorithm type.
Definition: CheckSum.h:48
static CheckSum sha512FromString(const std::string &input_r)
Definition: CheckSum.h:109
static const std::string & sha512Type()
Definition: CheckSum.cc:46
std::string _type
Definition: CheckSum.h:121
bool empty() const
Definition: CheckSum.cc:173
bool operator==(const CheckSum &lhs, const CheckSum &rhs)
std::string asString() const
Definition: CheckSum.cc:176
static CheckSum sha384(const std::string &checksum)
Definition: CheckSum.h:78
static const std::string & sha256Type()
Definition: CheckSum.cc:40
static CheckSum sha1(std::istream &&input_r)
Definition: CheckSum.h:94
static const std::string & sha384Type()
Definition: CheckSum.cc:43
static CheckSum sha512(std::istream &input_r)
Definition: CheckSum.h:90
static CheckSum sha1(std::istream &input_r)
Definition: CheckSum.h:86
static CheckSum sha224(std::istream &&input_r)
Definition: CheckSum.h:95
static CheckSum sha384(std::istream &input_r)
Definition: CheckSum.h:89
static const std::string & shaType()
Definition: CheckSum.cc:31
static CheckSum sha1(const std::string &checksum)
Definition: CheckSum.h:75
static CheckSum sha384(std::istream &&input_r)
Definition: CheckSum.h:97
static const std::string & sha1Type()
Definition: CheckSum.cc:34
static const std::string & sha224Type()
Definition: CheckSum.cc:37
static const std::string & md5Type()
Definition: CheckSum.cc:28
static CheckSum sha256(std::istream &input_r)
Definition: CheckSum.h:88
CheckSum(const std::string &type, std::istream &&input_r)
Ctor from temporary istream.
Definition: CheckSum.h:58
static CheckSum md5FromString(const std::string &input_r)
Definition: CheckSum.h:103
static CheckSum sha(std::istream &&input_r)
Definition: CheckSum.h:93
static CheckSum sha224(std::istream &input_r)
Definition: CheckSum.h:87
std::string type() const
Definition: CheckSum.cc:167
std::string checksum() const
Definition: CheckSum.cc:170
static CheckSum sha512(const std::string &checksum)
Definition: CheckSum.h:79
static CheckSum sha384FromString(const std::string &input_r)
Definition: CheckSum.h:108
static CheckSum md5(std::istream &input_r)
Definition: CheckSum.h:84
static CheckSum sha256(const std::string &checksum)
Definition: CheckSum.h:77
static CheckSum sha(const std::string &checksum)
Definition: CheckSum.h:74
static CheckSum sha256(std::istream &&input_r)
Definition: CheckSum.h:96
static CheckSum sha(std::istream &input_r)
Definition: CheckSum.h:85
static CheckSum shaFromString(const std::string &input_r)
Definition: CheckSum.h:104
CheckSum()
Default Ctor: empty checksum.
Definition: CheckSum.h:37
bool operator!=(const CheckSum &lhs, const CheckSum &rhs)
std::string _checksum
Definition: CheckSum.h:122
static CheckSum sha256FromString(const std::string &input_r)
Definition: CheckSum.h:107
static CheckSum sha224(const std::string &checksum)
Definition: CheckSum.h:76
Base class for Exception.
Definition: Exception.h:146
const std::string & msg() const
Return the message string provided to the ctor.
Definition: Exception.h:195
Definition: Arch.h:348
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & dumpAsXmlOn(std::ostream &str, const Repository &obj)
Definition: Repository.cc:406
std::ostream & operator<<(std::ostream &str, const InputStream &obj)
Definition: InputStream.cc:166
CheckSumException(const std::string &msg)
Definition: CheckSum.h:28