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 _KMDBASE_H
00035 #define _KMDBASE_H
00036
00037 #define KBase64 KCodecs
00038
00039 #include <qglobal.h>
00040 #include <qstring.h>
00041 #include <qiodevice.h>
00042 #include "kdelibs_export.h"
00043
00074 class KDECORE_EXPORT KCodecs
00075 {
00076 public:
00077
00087 static QCString quotedPrintableEncode(const QByteArray & in,
00088 bool useCRLF = true);
00089
00102 static QCString quotedPrintableEncode(const QCString & str,
00103 bool useCRLF = true);
00104
00124 static void quotedPrintableEncode(const QByteArray & in, QByteArray& out,
00125 bool useCRLF);
00126
00135 static QCString quotedPrintableDecode(const QByteArray & in);
00136
00146 static QCString quotedPrintableDecode(const QCString & str);
00147
00167 static void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
00168
00169
00181 static QCString uuencode( const QByteArray& in );
00182
00192 static QCString uuencode( const QCString& str );
00193
00209 static void uuencode( const QByteArray& in, QByteArray& out );
00210
00221 static QCString uudecode( const QByteArray& in );
00222
00232 static QCString uudecode( const QCString& str );
00233
00253 static void uudecode( const QByteArray& in, QByteArray& out );
00254
00255
00269 static QCString base64Encode( const QByteArray& in, bool insertLFs = false);
00270
00281 static QCString base64Encode( const QCString& str, bool insertLFs = false );
00282
00304 static void base64Encode( const QByteArray& in, QByteArray& out,
00305 bool insertLFs = false );
00306
00314 static QCString base64Decode( const QByteArray& in );
00315
00325 static QCString base64Decode( const QCString& str );
00326
00344 static void base64Decode( const QByteArray& in, QByteArray& out );
00345
00346
00347 private:
00348 KCodecs();
00349
00350 private:
00351 static const char UUEncMap[64];
00352 static const char UUDecMap[128];
00353 static const char Base64EncMap[64];
00354 static const char Base64DecMap[128];
00355 static const char hexChars[16];
00356 static const unsigned int maxQPLineLength;
00357 };
00358
00359 class KMD5Private;
00405 class KDECORE_EXPORT KMD5
00406 {
00407 public:
00408
00409 typedef unsigned char Digest[16];
00410
00411 KMD5();
00412
00421 KMD5(const char* in, int len = -1);
00422
00428 KMD5(const QByteArray& a );
00429
00435 KMD5(const QCString& a );
00436
00445 void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
00446
00450 void update(const unsigned char* in, int len = -1);
00451
00457 void update(const QByteArray& in );
00458
00464 void update(const QCString& in );
00465
00477 bool update(QIODevice& file);
00478
00484 void reset();
00485
00489 const Digest& rawDigest ();
00490
00500 void rawDigest( KMD5::Digest& bin );
00501
00506 QCString hexDigest ();
00507
00511 void hexDigest(QCString&);
00512
00517 QCString base64Digest ();
00518
00523 bool verify( const KMD5::Digest& digest);
00524
00528 bool verify(const QCString&);
00529
00530 protected:
00535 void transform( const unsigned char buffer[64] );
00536
00540 void finalize();
00541
00542 private:
00543 KMD5(const KMD5& u);
00544 KMD5& operator=(const KMD5& md);
00545
00546 void init();
00547 void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len );
00548 void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len );
00549
00550 Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
00551 Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00552 Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00553 Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00554 Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00555 void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00556 Q_UINT32 s, Q_UINT32 ac );
00557 void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00558 Q_UINT32 s, Q_UINT32 ac );
00559 void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00560 Q_UINT32 s, Q_UINT32 ac );
00561 void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00562 Q_UINT32 s, Q_UINT32 ac );
00563
00564 private:
00565 Q_UINT32 m_state[4];
00566 Q_UINT32 m_count[2];
00567 Q_UINT8 m_buffer[64];
00568 Digest m_digest;
00569 bool m_finalized;
00570
00571 KMD5Private* d;
00572 };
00573
00574
00575 #endif