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 #ifndef _QMDCODEC_H
00035 #define _QMDCODEC_H
00036
00037 #define QBase64 QCodecs
00038
00039 #include <qglobal.h>
00040 #include <qstring.h>
00041 #include <qiodevice.h>
00042
00043 #include "mythexp.h"
00044
00073 class MPUBLIC QCodecs
00074 {
00075 public:
00076
00086 static QCString quotedPrintableEncode(const QByteArray & in,
00087 bool useCRLF = true);
00088
00101 static QCString quotedPrintableEncode(const QCString & str,
00102 bool useCRLF = true);
00103
00123 static void quotedPrintableEncode(const QByteArray & in, QByteArray& out,
00124 bool useCRLF);
00125
00134 static QCString quotedPrintableDecode(const QByteArray & in);
00135
00145 static QCString quotedPrintableDecode(const QCString & str);
00146
00166 static void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
00167
00168
00180 static QCString uuencode( const QByteArray& in );
00181
00191 static QCString uuencode( const QCString& str );
00192
00208 static void uuencode( const QByteArray& in, QByteArray& out );
00209
00220 static QCString uudecode( const QByteArray& in );
00221
00231 static QCString uudecode( const QCString& str );
00232
00252 static void uudecode( const QByteArray& in, QByteArray& out );
00253
00254
00268 static QCString base64Encode( const QByteArray& in, bool insertLFs = false);
00269
00280 static QCString base64Encode( const QCString& str, bool insertLFs = false );
00281
00303 static void base64Encode( const QByteArray& in, QByteArray& out,
00304 bool insertLFs = false );
00305
00313 static QCString base64Decode( const QByteArray& in );
00314
00324 static QCString base64Decode( const QCString& str );
00325
00343 static void base64Decode( const QByteArray& in, QByteArray& out );
00344
00345
00346 private:
00347 QCodecs();
00348
00349 private:
00350 static const char UUEncMap[64];
00351 static const char UUDecMap[128];
00352 static const char Base64EncMap[64];
00353 static const char Base64DecMap[128];
00354 static const char hexChars[16];
00355 static const unsigned int maxQPLineLength;
00356 };
00357
00358 class QMD5Private;
00406 class MPUBLIC QMD5
00407 {
00408 public:
00409
00410 typedef unsigned char Digest[16];
00411
00412 QMD5();
00413
00422 QMD5(const char* in, int len = -1);
00423
00429 QMD5(const QByteArray& a );
00430
00436 QMD5(const QCString& a );
00437
00446 void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
00447
00451 void update(const unsigned char* in, int len = -1);
00452
00458 void update(const QByteArray& in );
00459
00465 void update(const QCString& in );
00466
00478 bool update(QIODevice& file);
00479
00485 void reset();
00486
00490 const Digest& rawDigest ();
00491
00501 void rawDigest( QMD5::Digest& bin );
00502
00507 QCString hexDigest ();
00508
00512 void hexDigest(QCString&);
00513
00518 QCString base64Digest ();
00519
00524 bool verify( const QMD5::Digest& digest);
00525
00529 bool verify(const QCString&);
00530
00531 protected:
00536 void transform( const unsigned char buffer[64] );
00537
00541 void finalize();
00542
00543 private:
00544 QMD5(const QMD5& u);
00545 QMD5& operator=(const QMD5& md);
00546
00547 void init();
00548 void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len );
00549 void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len );
00550
00551 Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
00552 Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00553 Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00554 Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00555 Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00556 void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00557 Q_UINT32 s, Q_UINT32 ac );
00558 void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00559 Q_UINT32 s, Q_UINT32 ac );
00560 void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00561 Q_UINT32 s, Q_UINT32 ac );
00562 void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00563 Q_UINT32 s, Q_UINT32 ac );
00564
00565 private:
00566 Q_UINT32 m_state[4];
00567 Q_UINT32 m_count[2];
00568 Q_UINT8 m_buffer[64];
00569 Digest m_digest;
00570 bool m_finalized;
00571
00572 QMD5Private* d;
00573 };
00574 #endif