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 unsigned short crc16;
00155
00156 protected:
00157 int overflow(int c);
00158
00159 std::ostream &strDigest(std::ostream &os);
00160
00161 public:
00162 CRC16Digest();
00163
00164 inline void initDigest(void)
00165 {crc16 = 0;};
00166
00167 inline unsigned getSize(void)
00168 {return 2;};
00169
00170 unsigned getDigest(unsigned char *buffer);
00171
00172 void putDigest(const unsigned char *buffer, unsigned length);
00173 };
00174
00182 class __EXPORT CRC32Digest : public Digest
00183 {
00184 private:
00185 unsigned long crc_table[256];
00186 unsigned long crc_reg;
00187 unsigned long crc32;
00188
00189 protected:
00190 unsigned char overflow(unsigned char octet);
00191
00192 std::ostream &strDigest(std::ostream &os);
00193
00194 public:
00195 CRC32Digest();
00196
00197 void initDigest(void);
00198
00199 inline unsigned getSize(void) {return 4;}
00200
00201 unsigned getDigest(unsigned char *buffer);
00202
00203 void putDigest(const unsigned char *buffer, unsigned length);
00204 };
00205
00212 class __EXPORT MD5Digest : public Digest
00213 {
00214 private:
00215 unsigned long state[4];
00216 unsigned long count[2];
00217 unsigned char buf[64];
00218 unsigned bpos;
00219 unsigned char md5[16];
00220 bool updated;
00221
00222 protected:
00223 int overflow(int c);
00224
00225 void update(void);
00226
00227 void commit(void);
00228
00229 std::ostream &strDigest(std::ostream &os);
00230
00231 public:
00232 MD5Digest();
00233
00234 void initDigest(void);
00235
00236 inline unsigned getSize(void)
00237 {return 16;};
00238
00239 unsigned getDigest(unsigned char *buffer);
00240
00241 void putDigest(const unsigned char *buffer, unsigned len);
00242 };
00243
00244 #ifdef COMMON_STD_EXCEPTION
00245
00254 class __EXPORT DigestException : public Exception {
00255 public:
00256 DigestException(const String &str) : Exception(str) {};
00257 };
00258 #endif
00259
00260 #ifdef CCXX_NAMESPACES
00261 }
00262 #endif
00263
00264 #endif
00265