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
00120 class __EXPORT ChecksumDigest : public Digest
00121 {
00122 private:
00123 unsigned char csum;
00124
00125 protected:
00126 int overflow(int c);
00127 std::ostream &strDigest(std::ostream &os);
00128
00129 public:
00130 ChecksumDigest();
00131
00132 void initDigest(void)
00133 {csum = 0;};
00134
00135 unsigned getSize(void)
00136 {return 1;};
00137
00138 unsigned getDigest(unsigned char *buffer);
00139
00140 void putDigest(const unsigned char *buffer, unsigned length);
00141 };
00142
00149 class __EXPORT CRC16Digest : public Digest
00150 {
00151 private:
00152 unsigned short crc16;
00153
00154 protected:
00155 int overflow(int c);
00156
00157 std::ostream &strDigest(std::ostream &os);
00158
00159 public:
00160 CRC16Digest();
00161
00162 inline void initDigest(void)
00163 {crc16 = 0;};
00164
00165 inline unsigned getSize(void)
00166 {return 2;};
00167
00168 unsigned getDigest(unsigned char *buffer);
00169
00170 void putDigest(const unsigned char *buffer, unsigned length);
00171 };
00172
00180 class __EXPORT CRC32Digest : public Digest
00181 {
00182 private:
00183 unsigned long crc_table[256];
00184 unsigned long crc_reg;
00185 unsigned long crc32;
00186
00187 protected:
00188 unsigned char overflow(unsigned char octet);
00189
00190 std::ostream &strDigest(std::ostream &os);
00191
00192 public:
00193 CRC32Digest();
00194
00195 void initDigest(void);
00196
00197 inline unsigned getSize(void) {return 4;}
00198
00199 unsigned getDigest(unsigned char *buffer);
00200
00201 void putDigest(const unsigned char *buffer, unsigned length);
00202 };
00203
00210 class __EXPORT MD5Digest : public Digest
00211 {
00212 private:
00213 unsigned long state[4];
00214 unsigned long count[2];
00215 unsigned char buf[64];
00216 unsigned bpos;
00217 unsigned char md5[16];
00218 bool updated;
00219
00220 protected:
00221 int overflow(int c);
00222
00223 void update(void);
00224
00225 void commit(void);
00226
00227 std::ostream &strDigest(std::ostream &os);
00228
00229 public:
00230 MD5Digest();
00231
00232 void initDigest(void);
00233
00234 inline unsigned getSize(void)
00235 {return 16;};
00236
00237 unsigned getDigest(unsigned char *buffer);
00238
00239 void putDigest(const unsigned char *buffer, unsigned len);
00240 };
00241
00242 #ifdef COMMON_STD_EXCEPTION
00243
00252 class __EXPORT DigestException : public Exception {
00253 public:
00254 DigestException(const String &str) : Exception(str) {};
00255 };
00256 #endif
00257
00258 #ifdef CCXX_NAMESPACES
00259 }
00260 #endif
00261
00262 #endif
00263