From: Michael Schroeder Date: Fri, 18 Jun 2010 10:19:20 +0000 (+0200) Subject: add digestVector() and digestReset() functions, fix bug in cleanup() function X-Git-Tag: 8.0.1~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c03041c3939764fc320cc9499227923d9a9f874c;p=platform%2Fupstream%2Flibzypp.git add digestVector() and digestReset() functions, fix bug in cleanup() function --- diff --git a/zypp/Digest.cc b/zypp/Digest.cc index 091555f..fcbe997 100644 --- a/zypp/Digest.cc +++ b/zypp/Digest.cc @@ -121,6 +121,7 @@ namespace zypp { { EVP_MD_CTX_cleanup(&mdctx); initialized = false; + finalized = false; } } @@ -150,6 +151,21 @@ namespace zypp { return _dp->name; } + bool Digest::reset() + { + if (!_dp->initialized) + return false; + if(!_dp->finalized) + { + (void)EVP_DigestFinal_ex(&_dp->mdctx, _dp->md_value, &_dp->md_len); + _dp->finalized = true; + } + if(!EVP_DigestInit_ex(&_dp->mdctx, _dp->md, NULL)) + return false; + _dp->finalized = false; + return true; + } + std::string Digest::digest() { if(!_dp->maybeInit()) @@ -174,6 +190,24 @@ namespace zypp { return std::string(mdtxt); } + std::vector Digest::digestVector() + { + std::vector r; + if(!_dp->maybeInit()) + return r; + + if(!_dp->finalized) + { + if(!EVP_DigestFinal_ex(&_dp->mdctx, _dp->md_value, &_dp->md_len)) + return r; + _dp->finalized = true; + } + r.reserve(_dp->md_len); + for(unsigned i = 0; i < _dp->md_len; ++i) + r.push_back(_dp->md_value[i]); + return r; + } + bool Digest::update(const char* bytes, size_t len) { if(!bytes) diff --git a/zypp/Digest.h b/zypp/Digest.h index 4b1937f..69556bf 100644 --- a/zypp/Digest.h +++ b/zypp/Digest.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -101,6 +102,22 @@ namespace zypp { * */ std::string digest(); + /** \brief get vector of unsigned char representation of the digest + * + * this function will finalize the digest computation. calls to update + * after this function will start from scratch + * + * @return vector representation of the digest + * */ + std::vector digestVector(); + + /** \brief reset internal digest state + * + * this function is equivalent to calling create() with an unchanged name, + * but it may be implemented in a more efficient way. + */ + bool reset(); + /** \brief compute digest of a stream. convenience function * * calls create, update and digest in one function. The data for the