Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:11

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