15#include <zypp-core/base/Logger.h>
16#include <zypp-core/base/Gettext.h>
17#include <zypp-core/base/String.h>
19#include <zypp-core/CheckSum.h>
20#include <zypp-core/Digest.h>
32 {
static std::string
_type(
"sha" );
return _type; }
56 if ( _type == sha512Type() )
58 if ( _type.empty() || _type == shaType() )
67 if ( _type == sha384Type() )
69 if ( _type.empty() || _type == shaType() )
78 if ( _type == sha256Type() )
80 if ( _type.empty() || _type == shaType() )
89 if ( _type == sha224Type() )
91 if ( _type.empty() || _type == shaType() )
100 if ( _type == sha1Type() )
102 if ( _type.empty() || _type == shaType() )
111 if ( _type == md5Type() )
128 WAR <<
"Can't determine type of " <<
checksum.size() <<
" byte checksum '" << _checksum <<
"'" << endl;
136 std::string msg = str::form (
_(
"Dubious type '%s' for %u byte checksum '%s'"),
137 _type.c_str(),
checksum.size(), _checksum.c_str() );
138 if ( _type == md5Type()
139 || _type == shaType()
140 || _type == sha1Type()
141 || _type == sha224Type()
142 || _type == sha256Type()
143 || _type == sha384Type()
144 || _type == sha512Type() )
154 CheckSum::CheckSum(
const std::string & type_r, std::istream & input_r )
156 if ( input_r.good() && ! type_r.empty() )
158 _type = str::toLower( type_r );
159 _checksum = Digest::digest( _type, input_r );
160 if ( ! input_r.eof() || _checksum.empty() )
162 _type = _checksum = std::string();
167 std::string CheckSum::type()
const
170 std::string CheckSum::checksum()
const
171 {
return _checksum; }
173 bool CheckSum::empty()
const
174 {
return (
checksum().empty() || type().empty()); }
176 std::string CheckSum::asString()
const
178 std::ostringstream
str;
183 std::ostream &
operator<<( std::ostream &
str,
const CheckSum & obj )
185 if ( obj.checksum().empty() )
187 return str << std::string(
"NoCheckSum");
190 return str << ( obj.type().empty() ? std::string(
"UNKNOWN") : obj.type() ) <<
'-' << obj.
checksum();
193 std::ostream &
dumpAsXmlOn( std::ostream &
str,
const CheckSum & obj )
195 const std::string & type( obj.type() );
196 const std::string &
checksum( obj.checksum() );
198 if ( ! type.empty() )
str <<
" type=\"" << type <<
"\"";
207 bool operator==(
const CheckSum & lhs,
const CheckSum & rhs )
208 {
return lhs.checksum() == rhs.checksum() && lhs.type() == rhs.type(); }
211 bool operator!=(
const CheckSum & lhs,
const CheckSum & rhs )
212 {
return ! ( lhs == rhs ); }
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
static const std::string & sha512Type()
static const std::string & sha256Type()
static const std::string & sha384Type()
static const std::string & shaType()
static const std::string & sha1Type()
static const std::string & sha224Type()
static const std::string & md5Type()
CheckSum()
Default Ctor: empty checksum.
static const std::string & md5()
md5
static const std::string & sha384()
sha384
static const std::string & sha512()
sha512
static const std::string & sha1()
sha1
static const std::string & sha256()
sha256
static const std::string & sha224()
sha224
String related utilities and Regular expression matching.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
std::string toLower(const std::string &s)
Return lowercase version of s.
Easy-to use interface to the ZYPP dependency resolver.
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...
std::ostream & dumpAsXmlOn(std::ostream &str, const Repository &obj)
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...
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.