Imported Upstream version 17.22.1
[platform/upstream/libzypp.git] / zypp / Digest.h
index c02d347..6e6075e 100644 (file)
@@ -6,7 +6,7 @@
 |                         /_____||_| |_| |_|                           |
 |                                                                      |
 \---------------------------------------------------------------------*/
-/** \file zypp//Digest.h
+/** \file zypp/Digest.h
  *
  * \todo replace by Blocxx
  *
 
 #include <string>
 #include <iosfwd>
+#include <vector>
 
-#include <zypp/Callback.h>
-#include <zypp/Pathname.h>
+#include "zypp/Callback.h"
+#include "zypp/Pathname.h"
 
 namespace zypp {
 
 
   struct DigestReport : public callback::ReportBase
   {
-    virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
-    { return true; }
-    virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
-    { return true; }
-    virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
-    { return true; }
+    virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file );
+    virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name );
+    virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found );
   };
-  
+
 
 
     /** \brief Compute Message Digests (MD5, SHA1 etc)
@@ -49,18 +47,35 @@ namespace zypp {
       private:
        class P;
        P* _dp;
-    
+
        // disabled
        Digest(const Digest& d);
        // disabled
        const Digest& operator=(const Digest& d);
-    
+
+      public:
+       /** \name Well known digest algorithm names. */
+       //@{
+       /** md5 */
+       static const std::string & md5();
+       /** sha1 */
+       static const std::string & sha1();
+       /** sha224 */
+       static const std::string & sha224();
+       /** sha256 */
+       static const std::string & sha256();
+       /** sha384 */
+       static const std::string & sha384();
+       /** sha512 */
+       static const std::string & sha512();
+       //@}
+
       public:
        Digest();
        ~Digest();
-    
+
        /** \brief initialize creation of a new message digest
-        * 
+        *
         * Since openssl is used as backend you may use anything that openssl
         * supports (see man 1 dgst). Common examples are md5 or sha1. sha1
         * should be preferred when creating digests to verify the authenticity
@@ -73,17 +88,24 @@ namespace zypp {
         * @return whether an error occured
         * */
        bool create(const std::string& name);
-    
+
        /** \brief get the name of the current digest algorithm */
        const std::string& name();
-    
+
        /** \brief feed data into digest computation algorithm
         * @param bytes
         * @param len
         * @return whether an error occured
         * */
        bool update(const char* bytes, size_t len);
-    
+
+        /** \brief feed data into digest computation algorithm
+        * @param is
+        * @param bufsize
+        * @return whether an error occured
+        * */
+        bool update(std::istream& is, size_t bufsize = 4096);
+
        /** \brief get hex string representation of the digest
         *
         * this function will finalize the digest computation. calls to update
@@ -92,7 +114,29 @@ namespace zypp {
         * @return hex string representation of the digest
         * */
        std::string digest();
-       
+
+        /** \brief get hex string representation of the digest vector given as parameter
+        *
+        * @return hex string representation of the digest
+        * */
+        static std::string digestVectorToString ( const std::vector<unsigned char> &vec );
+
+       /** \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<unsigned char> 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
@@ -104,8 +148,11 @@ namespace zypp {
         * @return the digest or empty on error
         * */
        static std::string digest(const std::string& name, std::istream& is, size_t bufsize = 4096);
+
+       /** \overload Reading input data from \c string. */
+       static std::string digest( const std::string & name, const std::string & input, size_t bufsize = 4096 );
     };
-    
+
 } // namespace zypp
 
 #endif