libzypp: zypp-core/CheckSum.h Source File

libzypp 17.38.14

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
23namespace 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:
37 CheckSum()
38 {}
39
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(), std::move(input_r) ); }
93 static CheckSum sha( std::istream && input_r ) { return CheckSum( sha1Type(), std::move(input_r) ); }
94 static CheckSum sha1( std::istream && input_r ) { return CheckSum( sha1Type(), std::move(input_r) ); }
95 static CheckSum sha224( std::istream && input_r ) { return CheckSum( sha224Type(), std::move(input_r) ); }
96 static CheckSum sha256( std::istream && input_r ) { return CheckSum( sha256Type(), std::move(input_r) ); }
97 static CheckSum sha384( std::istream && input_r ) { return CheckSum( sha384Type(), std::move(input_r) ); }
98 static CheckSum sha512( std::istream && input_r ) { return CheckSum( sha512Type(), std::move(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
Exception.h
Pathname.h
zypp::CheckSum
Definition CheckSum.h:34
zypp::CheckSum::md5
static CheckSum md5(std::istream &&input_r)
Definition CheckSum.h:92
zypp::CheckSum::sha224FromString
static CheckSum sha224FromString(const std::string &input_r)
Definition CheckSum.h:106
zypp::CheckSum::sha512
static CheckSum sha512(std::istream &&input_r)
Definition CheckSum.h:98
zypp::CheckSum::sha1FromString
static CheckSum sha1FromString(const std::string &input_r)
Definition CheckSum.h:105
zypp::CheckSum::md5
static CheckSum md5(const std::string &checksum)
Definition CheckSum.h:73
zypp::CheckSum::CheckSum
CheckSum(const std::string &checksum)
Creates a checksum auto probing the algorithm type.
Definition CheckSum.h:48
zypp::CheckSum::sha512FromString
static CheckSum sha512FromString(const std::string &input_r)
Definition CheckSum.h:109
zypp::CheckSum::sha512Type
static const std::string & sha512Type()
Definition CheckSum.cc:46
zypp::CheckSum::_type
std::string _type
Definition CheckSum.h:121
zypp::CheckSum::empty
bool empty() const
Definition CheckSum.cc:173
zypp::CheckSum::asString
std::string asString() const
Definition CheckSum.cc:176
zypp::CheckSum::sha384
static CheckSum sha384(const std::string &checksum)
Definition CheckSum.h:78
zypp::CheckSum::sha256Type
static const std::string & sha256Type()
Definition CheckSum.cc:40
zypp::CheckSum::sha1
static CheckSum sha1(std::istream &&input_r)
Definition CheckSum.h:94
zypp::CheckSum::sha384Type
static const std::string & sha384Type()
Definition CheckSum.cc:43
zypp::CheckSum::sha512
static CheckSum sha512(std::istream &input_r)
Definition CheckSum.h:90
zypp::CheckSum::sha1
static CheckSum sha1(std::istream &input_r)
Definition CheckSum.h:86
zypp::CheckSum::sha224
static CheckSum sha224(std::istream &&input_r)
Definition CheckSum.h:95
zypp::CheckSum::sha384
static CheckSum sha384(std::istream &input_r)
Definition CheckSum.h:89
zypp::CheckSum::shaType
static const std::string & shaType()
Definition CheckSum.cc:31
zypp::CheckSum::sha1
static CheckSum sha1(const std::string &checksum)
Definition CheckSum.h:75
zypp::CheckSum::sha384
static CheckSum sha384(std::istream &&input_r)
Definition CheckSum.h:97
zypp::CheckSum::sha1Type
static const std::string & sha1Type()
Definition CheckSum.cc:34
zypp::CheckSum::sha224Type
static const std::string & sha224Type()
Definition CheckSum.cc:37
zypp::CheckSum::md5Type
static const std::string & md5Type()
Definition CheckSum.cc:28
zypp::CheckSum::sha256
static CheckSum sha256(std::istream &input_r)
Definition CheckSum.h:88
zypp::CheckSum::CheckSum
CheckSum(const std::string &type, std::istream &&input_r)
Ctor from temporary istream.
Definition CheckSum.h:58
zypp::CheckSum::md5FromString
static CheckSum md5FromString(const std::string &input_r)
Definition CheckSum.h:103
zypp::CheckSum::sha
static CheckSum sha(std::istream &&input_r)
Definition CheckSum.h:93
zypp::CheckSum::sha224
static CheckSum sha224(std::istream &input_r)
Definition CheckSum.h:87
zypp::CheckSum::type
std::string type() const
Definition CheckSum.cc:167
zypp::CheckSum::checksum
std::string checksum() const
Definition CheckSum.cc:170
zypp::CheckSum::sha512
static CheckSum sha512(const std::string &checksum)
Definition CheckSum.h:79
zypp::CheckSum::sha384FromString
static CheckSum sha384FromString(const std::string &input_r)
Definition CheckSum.h:108
zypp::CheckSum::md5
static CheckSum md5(std::istream &input_r)
Definition CheckSum.h:84
zypp::CheckSum::sha256
static CheckSum sha256(const std::string &checksum)
Definition CheckSum.h:77
zypp::CheckSum::sha
static CheckSum sha(const std::string &checksum)
Definition CheckSum.h:74
zypp::CheckSum::sha256
static CheckSum sha256(std::istream &&input_r)
Definition CheckSum.h:96
zypp::CheckSum::sha
static CheckSum sha(std::istream &input_r)
Definition CheckSum.h:85
zypp::CheckSum::shaFromString
static CheckSum shaFromString(const std::string &input_r)
Definition CheckSum.h:104
zypp::CheckSum::CheckSum
CheckSum()
Default Ctor: empty checksum.
Definition CheckSum.h:37
zypp::CheckSum::_checksum
std::string _checksum
Definition CheckSum.h:122
zypp::CheckSum::sha256FromString
static CheckSum sha256FromString(const std::string &input_r)
Definition CheckSum.h:107
zypp::CheckSum::sha224
static CheckSum sha224(const std::string &checksum)
Definition CheckSum.h:76
zypp::Exception::Exception
Exception()
Default ctor.
Definition Exception.cc:94
zypp::Exception::msg
const std::string & msg() const
Return the message string provided to the ctor.
Definition Exception.h:206
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::dumpAsXmlOn
std::ostream & dumpAsXmlOn(std::ostream &str, const Repository &obj)
relates: Repository XML output
Definition Repository.cc:411
zypp::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
zypp::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::CheckSumException::CheckSumException
CheckSumException(const std::string &msg)
Definition CheckSum.h:28