1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Digest.h
11 * \todo replace by Blocxx
15 #ifndef ZYPP_MEDIA_DIGEST_H
16 #define ZYPP_MEDIA_DIGEST_H
21 #include <zypp/Callback.h>
22 #include <zypp/Pathname.h>
27 struct DigestReport : public callback::ReportBase
29 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file );
30 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name );
31 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found );
36 /** \brief Compute Message Digests (MD5, SHA1 etc)
38 * The computation works by initializing the algorithm using create(). This
39 * will construct an internal state. successive calls to update() deliver the
40 * data for which the digest is to be computed. After all data has been
41 * deliverd, a call to digest() finalizes the computation and returns the
51 Digest(const Digest& d);
53 const Digest& operator=(const Digest& d);
56 /** \name Well known digest algorithm names. */
59 static const std::string & md5();
61 static const std::string & sha1();
63 static const std::string & sha256();
70 /** \brief initialize creation of a new message digest
72 * Since openssl is used as backend you may use anything that openssl
73 * supports (see man 1 dgst). Common examples are md5 or sha1. sha1
74 * should be preferred when creating digests to verify the authenticity
77 * successive calls to this funcion will destroy the internal state and
80 * @param name name of the message digest algorithm.
81 * @return whether an error occured
83 bool create(const std::string& name);
85 /** \brief get the name of the current digest algorithm */
86 const std::string& name();
88 /** \brief feed data into digest computation algorithm
91 * @return whether an error occured
93 bool update(const char* bytes, size_t len);
95 /** \brief get hex string representation of the digest
97 * this function will finalize the digest computation. calls to update
98 * after this function will start from scratch
100 * @return hex string representation of the digest
102 std::string digest();
104 /** \brief compute digest of a stream. convenience function
106 * calls create, update and digest in one function. The data for the
107 * computation is read from the stream
109 * @param name name of the digest algorithm, \see create
110 * @param is an input stream to get the data from
111 * @param bufsize size of the buffer used for update(). Be careful, this is on the stack.
112 * @return the digest or empty on error
114 static std::string digest(const std::string& name, std::istream& is, size_t bufsize = 4096);
116 /** \overload Reading input data from \c string. */
117 static std::string digest( const std::string & name, const std::string & input, size_t bufsize = 4096 );