Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/md5stream.h

00001 /* cxxtools/md5stream.h
00002  *
00003  * cxxtools - general purpose C++-toolbox
00004  * Copyright (C) 2003 Tommi Maekitalo
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6