Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:18

0001 #ifndef FWCore_Utilities_Digest_h
0002 #define FWCore_Utilities_Digest_h
0003 
0004 #include "md5.h"
0005 
0006 #include <iosfwd>
0007 #include <string>
0008 
0009 namespace cms {
0010 
0011   struct MD5Result {
0012     // The default-constructed MD5Result is invalid; all others are
0013     // valid. The MD5 digest of the empty string is the value of the
0014     // default-constructed MD5Result.
0015     MD5Result();
0016 
0017     // This is the MD5 digest.
0018     unsigned char bytes[16];
0019 
0020     // Convert the digest to a printable string (the 'hexdigest')
0021     std::string toString() const;
0022 
0023     // The MD5 digest (not hexdigest) in string form
0024     // 'std::basic_string<char>', rather than
0025     // 'unsigned char [16]'
0026     std::string compactForm() const;
0027 
0028     // Set our data from the given hexdigest string.
0029     void fromHexifiedString(std::string const& s);
0030 
0031     bool isValid() const;
0032   };
0033 
0034   bool operator==(MD5Result const& a, MD5Result const& b);
0035   bool operator<(MD5Result const& a, MD5Result const& b);
0036 
0037   inline bool operator!=(MD5Result const& a, MD5Result const& b) { return !(a == b); }
0038 
0039   inline std::ostream& operator<<(std::ostream& os, MD5Result const& r) {
0040     os << r.toString();
0041     return os;
0042   }
0043 
0044   // Digest creates an MD5 digest of the given string. The digest can
0045   // be updated by using 'append'.
0046   class Digest {
0047   public:
0048     Digest();
0049     explicit Digest(std::string const& s);
0050 
0051     void append(std::string const& s);
0052     void append(const char* data, size_t size);
0053 
0054     MD5Result digest();
0055 
0056   private:
0057     md5_state_t state_;
0058   };
0059 }  // namespace cms
0060 
0061 #endif