CMS 3D CMS Logo

Digest.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_Digest_h
2 #define FWCore_Utilities_Digest_h
3 
4 #include "md5.h"
5 
6 #include <iosfwd>
7 #include <string>
8 #include <array>
9 
10 namespace cms {
11 
12  struct MD5Result {
13  // The default-constructed MD5Result is invalid; all others are
14  // valid. The MD5 digest of the empty string is the value of the
15  // default-constructed MD5Result.
16  MD5Result();
17 
18  // This is the MD5 digest.
19  std::array<unsigned char, 16> bytes;
20 
21  // Convert the digest to a printable string (the 'hexdigest')
22  std::string toString() const;
23 
24  // The MD5 digest (not hexdigest) in string form
25  // 'std::basic_string<char>', rather than
26  // 'unsigned char [16]'
27  std::string compactForm() const;
28 
29  // Set our data from the given hexdigest string.
30  void fromHexifiedString(std::string const& s);
31 
32  bool isValid() const;
33  };
34 
35  bool operator==(MD5Result const& a, MD5Result const& b);
36  bool operator<(MD5Result const& a, MD5Result const& b);
37 
38  inline bool operator!=(MD5Result const& a, MD5Result const& b) { return !(a == b); }
39 
40  inline std::ostream& operator<<(std::ostream& os, MD5Result const& r) {
41  os << r.toString();
42  return os;
43  }
44 
45  // Digest creates an MD5 digest of the given string. The digest can
46  // be updated by using 'append'.
47  class Digest {
48  public:
49  Digest();
50  explicit Digest(std::string const& s);
51 
52  void append(std::string const& s);
53  void append(const char* data, size_t size);
54 
55  MD5Result digest();
56 
57  private:
58  md5_state_t state_;
59  };
60 } // namespace cms
61 
62 #endif
size
Write out results.
bool isValid() const
Definition: Digest.cc:139
void fromHexifiedString(std::string const &s)
Definition: Digest.cc:117
MD5Result digest()
Definition: Digest.cc:171
bool operator<(MD5Result const &a, MD5Result const &b)
Definition: Digest.cc:145
bool operator==(MD5Result const &a, MD5Result const &b)
Definition: Digest.cc:141
Namespace of DDCMS conversion namespace.
md5_state_t state_
Definition: Digest.h:58
std::array< unsigned char, 16 > bytes
Definition: Digest.h:19
std::string compactForm() const
Definition: Digest.cc:109
double b
Definition: hdecay.h:118
bool operator!=(MD5Result const &a, MD5Result const &b)
Definition: Digest.h:38
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
double a
Definition: hdecay.h:119
std::ostream & operator<<(std::ostream &os, MD5Result const &r)
Definition: Digest.h:40
std::string toString() const
Definition: Digest.cc:95
void append(std::string const &s)
Definition: Digest.cc:161