MD5Digest.h
Go to the documentation of this file.
1 #ifndef cetlib_MD5Digest_h
2 #define cetlib_MD5Digest_h
3 
4 #include <iosfwd>
5 #include <string>
6 #ifdef __APPLE__
7 #define COMMON_DIGEST_FOR_OPENSSL
8 #include <CommonCrypto/CommonDigest.h>
9 #undef COMMON_DIGEST_FOR_OPENSSL
10 #else
11 #include <openssl/md5.h>
12 #endif
13 
14 namespace cet {
15 
16  struct MD5Result {
17  // The default-constructed MD5Result is invalid; all others are
18  // valid. The MD5 digest of the empty string is the value of the
19  // default-constructed MD5Result.
20  MD5Result();
21 
22  // This is the MD5 digest.
23  unsigned char bytes[16];
24 
25  // Convert the digest to a printable string (the 'hexdigest')
26  std::string toString() const;
27 
28  // The MD5 digest (not hexdigest) in string form
29  // 'std::basic_string<char>', rather than
30  // 'unsigned char [16]'
31  std::string compactForm() const;
32 
33  // Set our data from the given hexdigest string.
34  void fromHexifiedString(std::string const& s);
35 
36  bool isValid() const;
37  };
38 
39  bool operator==(MD5Result const& a, MD5Result const& b);
40  bool operator<(MD5Result const& a, MD5Result const& b);
41 
42  inline bool
43  operator!=(MD5Result const& a, MD5Result const& b)
44  {
45  return !(a == b);
46  }
47 
48  inline std::ostream&
49  operator<<(std::ostream& os, MD5Result const& r)
50  {
51  os << r.toString();
52  return os;
53  }
54 
55  // Digest creates an MD5 digest of the given string. The digest can
56  // be updated by using 'append'.
57  class MD5Digest {
58  public:
59  MD5Digest();
60  explicit MD5Digest(std::string const& s);
61 
62  void append(std::string const& s);
63  MD5Result digest() const;
64 
65  private:
66  mutable MD5_CTX context_;
67  };
68 }
69 
70 #endif /* cetlib_MD5Digest_h */
71 
72 // Local Variables:
73 // mode: c++
74 // End:
bool isValid() const
std::ostream & operator<<(std::ostream &, map_vector_key const &)
Definition: map_vector.h:330
std::string toString() const
bool operator!=(exempt_ptr< E > const &, exempt_ptr< E > const &)
Definition: exempt_ptr.h:216
bool operator<(exempt_ptr< E > const &, exempt_ptr< E > const &)
Definition: exempt_ptr.h:254
MD5_CTX context_
Definition: MD5Digest.h:66
void append()
Definition: append.C:24
void fromHexifiedString(std::string const &s)
const XML_Char * s
Definition: expat.h:262
const double a
unsigned char bytes[16]
Definition: MD5Digest.h:23
bool operator==(exempt_ptr< E > const &, exempt_ptr< E > const &)
Definition: exempt_ptr.h:209
const hit & b
Definition: hits.cxx:21
TRandom3 r(0)
std::string compactForm() const
enum BeamMode string