00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CXXTOOLS_MD5STREAM_H
00023 #define CXXTOOLS_MD5STREAM_H
00024
00025 #include <cxxtools/md5.h>
00026 #include <iostream>
00027
00028 namespace cxxtools
00029 {
00030
00031 class Md5streambuf : public std::streambuf
00032 {
00033 public:
00034 Md5streambuf()
00035 { }
00036
00037 void getDigest(unsigned char digest[16]);
00038
00039 private:
00040 static const unsigned int bufsize = 64;
00041 char buffer[bufsize];
00042 cxxtools_MD5_CTX context;
00043 unsigned char digest[16];
00044
00045 std::streambuf::int_type overflow(std::streambuf::int_type ch);
00046 std::streambuf::int_type underflow();
00047 int sync();
00048 };
00049
00077 class Md5stream : public std::ostream
00078 {
00079 public:
00080 typedef std::ostreambuf_iterator<char> iterator;
00081
00082 private:
00083 Md5streambuf streambuf;
00084 char hexdigest[33];
00085
00086 public:
00088 Md5stream()
00089 : std::ostream(0)
00090 {
00091 init(&streambuf);
00092 }
00093
00095 void getDigest(unsigned char digest[16])
00096 { streambuf.getDigest(digest); }
00098 const char* getHexDigest();
00099
00101 iterator begin()
00102 { return iterator(&streambuf); }
00103 };
00104
00105 }
00106
00107 #endif // CXXTOOLS_MD5STREAM_H