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