libzypp  17.24.1
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 
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
zypp::CheckSum::sha
static CheckSum sha(std::istream &input_r)
Definition: CheckSum.h:85
zypp::CheckSum::sha256
static CheckSum sha256(std::istream &input_r)
Definition: CheckSum.h:88
zypp::CheckSum::sha256
static CheckSum sha256(const std::string &checksum)
Definition: CheckSum.h:77
zypp::CheckSum::type
std::string type() const
Definition: CheckSum.cc:167
zypp::Exception
Base class for Exception.
Definition: Exception.h:145
zypp::CheckSum::sha384FromString
static CheckSum sha384FromString(const std::string &input_r)
Definition: CheckSum.h:108
zypp::CheckSum
Definition: CheckSum.h:33
zypp::CheckSum::sha384Type
static const std::string & sha384Type()
Definition: CheckSum.cc:43
zypp::CheckSum::sha384
static CheckSum sha384(std::istream &&input_r)
Definition: CheckSum.h:97
zypp::CheckSum::sha224
static CheckSum sha224(std::istream &input_r)
Definition: CheckSum.h:87
zypp::CheckSum::sha
static CheckSum sha(std::istream &&input_r)
Definition: CheckSum.h:93
zypp::CheckSum::sha1
static CheckSum sha1(std::istream &&input_r)
Definition: CheckSum.h:94
zypp::dumpAsXmlOn
std::ostream & dumpAsXmlOn(std::ostream &str, const Tp &obj, const std::string &name_r)
Definition: Xml.h:213
zypp::CheckSum::md5
static CheckSum md5(std::istream &&input_r)
Definition: CheckSum.h:92
zypp::operator==
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:84
zypp::CheckSum::empty
bool empty() const
Definition: CheckSum.cc:173
Pathname.h
zypp::CheckSum::sha1Type
static const std::string & sha1Type()
Definition: CheckSum.cc:34
zypp::CheckSum::md5Type
static const std::string & md5Type()
Definition: CheckSum.cc:28
zypp::CheckSum::sha384
static CheckSum sha384(const std::string &checksum)
Definition: CheckSum.h:78
zypp::CheckSum::CheckSum
CheckSum()
Default Ctor: empty checksum.
Definition: CheckSum.h:37
zypp::CheckSum::sha512
static CheckSum sha512(std::istream &&input_r)
Definition: CheckSum.h:98
zypp::CheckSum::sha1
static CheckSum sha1(const std::string &checksum)
Definition: CheckSum.h:75
zypp::CheckSum::sha512
static CheckSum sha512(const std::string &checksum)
Definition: CheckSum.h:79
Exception.h
zypp::CheckSum::sha1FromString
static CheckSum sha1FromString(const std::string &input_r)
Definition: CheckSum.h:105
zypp::CheckSum::CheckSum
CheckSum(const std::string &type, std::istream &&input_r)
Ctor from temporary istream.
Definition: CheckSum.h:58
zypp::CheckSum::sha224
static CheckSum sha224(std::istream &&input_r)
Definition: CheckSum.h:95
zypp::CheckSumException::CheckSumException
CheckSumException(const std::string &msg)
Definition: CheckSum.h:28
zypp::CheckSum::sha224Type
static const std::string & sha224Type()
Definition: CheckSum.cc:37
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::CheckSum::sha224FromString
static CheckSum sha224FromString(const std::string &input_r)
Definition: CheckSum.h:106
zypp::CheckSum::sha
static CheckSum sha(const std::string &checksum)
Definition: CheckSum.h:74
zypp::CheckSum::asString
std::string asString() const
Definition: CheckSum.cc:176
zypp::CheckSum::CheckSum
CheckSum(const std::string &checksum)
Creates a checksum auto probing the algorithm type.
Definition: CheckSum.h:48
zypp::CheckSumException
Definition: CheckSum.h:26
zypp::CheckSum::shaFromString
static CheckSum shaFromString(const std::string &input_r)
Definition: CheckSum.h:104
zypp::operator!=
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:109
zypp::CheckSum::checksum
std::string checksum() const
Definition: CheckSum.cc:170
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
std
Definition: Arch.h:347
zypp::CheckSum::shaType
static const std::string & shaType()
Definition: CheckSum.cc:31
zypp::CheckSum::sha512FromString
static CheckSum sha512FromString(const std::string &input_r)
Definition: CheckSum.h:109
zypp::CheckSum::_checksum
std::string _checksum
Definition: CheckSum.h:122
zypp::CheckSum::md5
static CheckSum md5(const std::string &checksum)
Definition: CheckSum.h:73
zypp::CheckSum::sha1
static CheckSum sha1(std::istream &input_r)
Definition: CheckSum.h:86
zypp::CheckSum::md5
static CheckSum md5(std::istream &input_r)
Definition: CheckSum.h:84
str
String related utilities and Regular expression matching.
zypp::CheckSum::sha256
static CheckSum sha256(std::istream &&input_r)
Definition: CheckSum.h:96
zypp::CheckSum::_type
std::string _type
Definition: CheckSum.h:121
zypp::CheckSum::md5FromString
static CheckSum md5FromString(const std::string &input_r)
Definition: CheckSum.h:103
zypp::CheckSum::sha224
static CheckSum sha224(const std::string &checksum)
Definition: CheckSum.h:76
zypp::CheckSum::sha512Type
static const std::string & sha512Type()
Definition: CheckSum.cc:46
zypp::CheckSum::sha384
static CheckSum sha384(std::istream &input_r)
Definition: CheckSum.h:89
zypp::CheckSum::sha256Type
static const std::string & sha256Type()
Definition: CheckSum.cc:40
zypp::CheckSum::sha256FromString
static CheckSum sha256FromString(const std::string &input_r)
Definition: CheckSum.h:107
zypp::Exception::msg
const std::string & msg() const
Return the message string provided to the ctor.
Definition: Exception.h:195
zypp::CheckSum::sha512
static CheckSum sha512(std::istream &input_r)
Definition: CheckSum.h:90