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