Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

digest.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2001 Open Source Telecom Corporation.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release 
00019 // of Common C++.
00020 // 
00021 // The exception is that, if you link the Common C++ library with other
00022 // files to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the Common C++ library code into it.
00026 // 
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 // 
00030 // This exception applies only to the code released under the 
00031 // name Common C++.  If you copy code from other releases into a copy of
00032 // Common C++, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for Common C++, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.  
00040 
00041 #ifndef CCXX_DIGEST_H_
00042 #define CCXX_DIGEST_H_
00043 
00044 #ifndef CCXX_CONFIG_H_
00045 #include <cc++/config.h>
00046 #endif
00047 
00048 #ifndef CCXX_THREAD_H_
00049 #include <cc++/thread.h>
00050 #endif
00051 
00052 #include <iostream>
00053 #include <fstream>
00054 #include <strstream>
00055 
00056 #ifdef  CCXX_NAMESPACES
00057 namespace ost {
00058 #endif
00059 
00060 #ifdef WIN32
00061 class CCXX_CLASS_EXPORT Digest;
00062 class CCXX_CLASS_EXPORT ChecksumDigest;
00063 class CCXX_CLASS_EXPORT CRC16Digest;
00064 class CCXX_CLASS_EXPORT MD5Digest;
00065 #endif
00066 
00074 #if defined(STLPORT) || defined(__KCC)
00075 #define std::ostream std::ostream_withassign
00076 #endif
00077 class Digest : public std::streambuf, public std::ostream
00078 {
00079 protected:
00080         Digest();
00081 
00085         virtual void initDigest(void) = 0;
00086 
00092         virtual unsigned getSize(void) = 0;
00093 
00100         virtual unsigned getDigest(unsigned char *buffer) = 0;
00101 
00108         virtual void putDigest(unsigned char *buffer, unsigned length) = 0;
00109 
00115         virtual std::ostream &strDigest(std::ostream &os) = 0;
00116 
00117         friend std::ostream &operator<<(std::ostream &os, Digest &ia)
00118                 {return ia.strDigest(os);};
00119 };
00120 
00127 class ChecksumDigest : public Digest
00128 {
00129 private:
00130         unsigned char csum;
00131 
00132 protected:
00133         int overflow(int c);
00134         std::ostream &strDigest(std::ostream &os);
00135 
00136 public:
00137         ChecksumDigest();
00138 
00139         void initDigest(void)
00140                 {csum = 0;};
00141 
00142         unsigned getSize(void)
00143                 {return 1;};
00144 
00145         unsigned getDigest(unsigned char *buffer);
00146 
00147         void putDigest(unsigned char *buffer, unsigned length);
00148 };
00149 
00156 class CRC16Digest : public Digest
00157 {
00158 private:
00159         unsigned short crc16;
00160 
00161 protected:
00162         int overflow(int c);
00163 
00164         std::ostream &strDigest(std::ostream &os);
00165 
00166 public:
00167         CRC16Digest();
00168 
00169         inline void initDigest(void)
00170                 {crc16 = 0;};
00171 
00172         inline unsigned getSize(void)
00173                 {return 2;};
00174 
00175         unsigned getDigest(unsigned char *buffer);
00176 
00177         void putDigest(unsigned char *buffer, unsigned length);
00178 };
00179 
00186 class MD5Digest : public Digest
00187 {
00188 private:
00189         unsigned long state[4];
00190         unsigned long count[2];
00191         unsigned char buf[64];
00192         unsigned bpos;
00193         unsigned char md5[16];
00194         bool updated;
00195 
00196 protected:
00197         int overflow(int c);
00198 
00199         void Update(void);
00200 
00201         void Commit(void);
00202 
00203         std::ostream &strDigest(std::ostream &os);
00204 
00205 public:
00206         MD5Digest();
00207 
00208         void initDigest(void);
00209 
00210         inline unsigned getSize(void)
00211                 {return 16;};
00212 
00213         unsigned getDigest(unsigned char *buffer);
00214 
00215         void putDigest(unsigned char *buffer, unsigned len);
00216 };
00217 
00218 #ifdef  CCXX_NAMESPACES
00219 };
00220 #endif
00221 
00222 #endif
00223 

Generated at Fri Dec 21 08:31:29 2001 for CommonC++ by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001