CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Utilities/interface/Digest.h

Go to the documentation of this file.
00001 #ifndef FWCore_Utilities_Digest_h
00002 #define FWCore_Utilities_Digest_h
00003 
00004 #include "FWCore/Utilities/interface/md5.h"
00005 
00006 #include <iosfwd>
00007 #include <string>
00008 
00009 
00010 namespace cms
00011 {
00012 
00013   struct MD5Result
00014   {
00015     // The default-constructed MD5Result is invalid; all others are
00016     // valid. The MD5 digest of the empty string is the value of the
00017     // default-constructed MD5Result.
00018     MD5Result();
00019 
00020     // This is the MD5 digest.
00021     unsigned char bytes[16];
00022 
00023     // Convert the digest to a printable string (the 'hexdigest')
00024     std::string toString() const;
00025 
00026     // The MD5 digest (not hexdigest) in string form
00027     // 'std::basic_string<char>', rather than
00028     // 'unsigned char [16]'
00029     std::string compactForm() const;
00030 
00031     // Set our data from the given hexdigest string.
00032     void fromHexifiedString(std::string const& s);
00033 
00034     bool isValid() const;
00035   };
00036 
00037   bool operator==(MD5Result const& a, MD5Result const& b);
00038   bool operator< (MD5Result const& a, MD5Result const& b);
00039 
00040   inline bool operator!=(MD5Result const& a, MD5Result const& b)
00041   {
00042     return !(a==b);
00043   }
00044 
00045   inline
00046   std::ostream& operator<< (std::ostream& os, MD5Result const& r)
00047   {
00048     os << r.toString();
00049     return os;
00050   }
00051 
00052   // Digest creates an MD5 digest of the given string. The digest can
00053   // be updated by using 'append'.
00054   class Digest
00055   {
00056   public:
00057     Digest();
00058     explicit Digest(std::string const& s);
00059 
00060     void append(std::string const& s);
00061     void append(const char *data, size_t size);
00062 
00063     MD5Result digest() const;
00064 
00065   private:
00066     mutable md5_state_t state_;
00067   };
00068 }
00069 
00070 #endif