00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00044 #ifndef CCXX_DIGEST_H_
00045 #define CCXX_DIGEST_H_
00046
00047 #ifndef CCXX_MISSING_H_
00048 #include <cc++/missing.h>
00049 #endif
00050
00051 #ifndef CCXX_THREAD_H_
00052 #include <cc++/thread.h>
00053 #endif
00054
00055 #ifndef CCXX_EXCEPTION_H_
00056 #include <cc++/exception.h>
00057 #endif
00058
00059 #ifdef CCXX_NAMESPACES
00060 namespace ost {
00061 #endif
00062
00070 class __EXPORT Digest : protected std::streambuf, public std::ostream
00071 {
00072 protected:
00073 Digest();
00074
00080 virtual unsigned getSize(void) = 0;
00081
00088 virtual unsigned getDigest(unsigned char *buffer) = 0;
00089
00096 virtual void putDigest(const unsigned char *buffer, unsigned length) = 0;
00097
00103 virtual std::ostream &strDigest(std::ostream &os) = 0;
00104
00105 friend std::ostream &operator<<(std::ostream &os, Digest &ia)
00106 {return ia.strDigest(os);};
00107
00108 public:
00112 virtual void initDigest(void) = 0;
00113
00114 virtual ~Digest();
00115 };
00116
00123 class __EXPORT ChecksumDigest : public Digest
00124 {
00125 private:
00126 unsigned char csum;
00127
00128 protected:
00129 int overflow(int c);
00130 std::ostream &strDigest(std::ostream &os);
00131
00132 public:
00133 ChecksumDigest();
00134
00135 void initDigest(void)
00136 {csum = 0;};
00137
00138 unsigned getSize(void)
00139 {return 1;};
00140
00141 unsigned getDigest(unsigned char *buffer);
00142
00143 void putDigest(const unsigned char *buffer, unsigned length);
00144 };
00145
00152 class __EXPORT CRC16Digest : public Digest
00153 {
00154 private:
00155 uint16 crc16;
00156
00157 protected:
00158 int overflow(int c);
00159
00160 std::ostream &strDigest(std::ostream &os);
00161
00162 public:
00163 CRC16Digest();
00164
00165 CRC16Digest ( const CRC16Digest &crc );
00166
00167 virtual ~CRC16Digest() {};
00168
00169 inline void initDigest(uint16 crc) {crc16 = crc;};
00170
00171 void initDigest(void) {initDigest(0);};
00172
00173 inline unsigned getSize ( void )
00174 {return sizeof(crc16);};
00175
00176 CRC16Digest& operator= ( const CRC16Digest &right );
00177
00178 operator const uint16() const
00179 {return crc16;};
00180
00181 inline uint16 getDigest(void)
00182 {return crc16;};
00183
00184 unsigned getDigest ( unsigned char *buffer );
00185
00186 void putDigest ( const unsigned char *buffer, unsigned length );
00187
00188 };
00189
00197 class __EXPORT CRC32Digest : public Digest
00198 {
00199 private:
00200 uint32 crc_table[256];
00201 uint32 crc_reg;
00202 uint32 crc32;
00203
00204 protected:
00205 unsigned char overflow(unsigned char octet);
00206
00207 std::ostream &strDigest(std::ostream &os);
00208
00209 public:
00210 CRC32Digest();
00211 CRC32Digest(const CRC32Digest &crc);
00212
00213 void initDigest(void);
00214
00215 inline unsigned getSize(void) {return sizeof(crc32);}
00216
00217 operator const uint32() const
00218 {return crc32;};
00219
00220 inline uint32 getDigest(void)
00221 {return crc32;};
00222
00223 unsigned getDigest(unsigned char *buffer);
00224
00225 void putDigest(const unsigned char *buffer, unsigned length);
00226
00227 CRC32Digest& operator= (const CRC32Digest &right);
00228 };
00229
00236 class __EXPORT MD5Digest : public Digest
00237 {
00238 private:
00239 unsigned long state[4];
00240 unsigned long count[2];
00241 unsigned char buf[64];
00242 unsigned bpos;
00243 unsigned char md5[16];
00244 bool updated;
00245
00246 protected:
00247 int overflow(int c);
00248
00249 void update(void);
00250
00251 void commit(void);
00252
00253 std::ostream &strDigest(std::ostream &os);
00254
00255 public:
00256 MD5Digest();
00257
00258 void initDigest(void);
00259
00260 inline unsigned getSize(void)
00261 {return 16;};
00262
00263 unsigned getDigest(unsigned char *buffer);
00264
00265 void putDigest(const unsigned char *buffer, unsigned len);
00266 };
00267
00268 #ifdef COMMON_STD_EXCEPTION
00269
00278 class __EXPORT DigestException : public Exception {
00279 public:
00280 DigestException(const String &str) : Exception(str) {};
00281 };
00282 #endif
00283
00284 #ifdef CCXX_NAMESPACES
00285 }
00286 #endif
00287
00288 #endif
00289