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
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
00164 static void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
00165
00166
00178 static QCString uuencode( const QByteArray& in );
00179
00189 static QCString uuencode( const QCString& str );
00190
00206 static void uuencode( const QByteArray& in, QByteArray& out );
00207
00218 static QCString uudecode( const QByteArray& in );
00219
00229 static QCString uudecode( const QCString& str );
00230
00250 static void uudecode( const QByteArray& in, QByteArray& out );
00251
00252
00266 static QCString base64Encode( const QByteArray& in, bool insertLFs = false);
00267
00278 static QCString base64Encode( const QCString& str, bool insertLFs = false );
00279
00301 static void base64Encode( const QByteArray& in, QByteArray& out,
00302 bool insertLFs = false );
00303
00311 static QCString base64Decode( const QByteArray& in );
00312
00322 static QCString base64Decode( const QCString& str );
00323
00341 static void base64Decode( const QByteArray& in, QByteArray& out );
00342
00343
00344 private:
00345 KCodecs();
00346
00347 private:
00348 static const char UUEncMap[64];
00349 static const char UUDecMap[128];
00350 static const char Base64EncMap[64];
00351 static const char Base64DecMap[128];
00352 static const char hexChars[16];
00353 static const unsigned int maxQPLineLength;
00354 };
00355
00356 class KMD5Private;
00402 class KDECORE_EXPORT KMD5
00403 {
00404 public:
00405
00406 typedef unsigned char Digest[16];
00407
00408 KMD5();
00409
00418 KMD5(const char* in, int len = -1);
00419
00425 KMD5(const QByteArray& a );
00426
00432 KMD5(const QCString& a );
00433
00442 void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
00443
00447 void update(const unsigned char* in, int len = -1);
00448
00454 void update(const QByteArray& in );
00455
00461 void update(const QCString& in );
00462
00474 bool update(QIODevice& file);
00475
00481 void reset();
00482
00486 const Digest& rawDigest ();
00487
00497 void rawDigest( KMD5::Digest& bin );
00498
00503 QCString hexDigest ();
00504
00508 void hexDigest(QCString&);
00509
00514 QCString base64Digest ();
00515
00520 bool verify( const KMD5::Digest& digest);
00521
00525 bool verify(const QCString&);
00526
00527 protected:
00532 void transform( const unsigned char buffer[64] );
00533
00537 void finalize();
00538
00539 private:
00540 KMD5(const KMD5& u);
00541 KMD5& operator=(const KMD5& md);
00542
00543 void init();
00544 void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len );
00545 void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len );
00546
00547 Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
00548 Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00549 Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00550 Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00551 Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00552 void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00553 Q_UINT32 s, Q_UINT32 ac );
00554 void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00555 Q_UINT32 s, Q_UINT32 ac );
00556 void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00557 Q_UINT32 s, Q_UINT32 ac );
00558 void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00559 Q_UINT32 s, Q_UINT32 ac );
00560
00561 private:
00562 Q_UINT32 m_state[4];
00563 Q_UINT32 m_count[2];
00564 Q_UINT8 m_buffer[64];
00565 Digest m_digest;
00566 bool m_finalized;
00567
00568 KMD5Private* d;
00569 };
00570
00577 class KDECORE_EXPORT KMD4
00578 {
00579 public:
00580
00581 typedef unsigned char Digest[16];
00582
00583 KMD4();
00584
00593 KMD4(const char* in, int len = -1);
00594
00600 KMD4(const QByteArray& a );
00601
00607 KMD4(const QCString& a );
00608
00617 void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
00618
00622 void update(const unsigned char* in, int len = -1);
00623
00629 void update(const QByteArray& in );
00630
00636 void update(const QCString& in );
00637
00649 bool update(QIODevice& file);
00650
00656 void reset();
00657
00661 const Digest& rawDigest ();
00662
00672 void rawDigest( KMD4::Digest& bin );
00673
00678 QCString hexDigest ();
00679
00683 void hexDigest(QCString&);
00684
00689 QCString base64Digest ();
00690
00695 bool verify( const KMD4::Digest& digest);
00696
00700 bool verify(const QCString&);
00701
00702 protected:
00707 void transform( Q_UINT32 buf[4], Q_UINT32 const in[16] );
00708
00712 void finalize();
00713
00714 private:
00715 KMD4(const KMD4& u);
00716 KMD4& operator=(const KMD4& md);
00717
00718 void init();
00719
00720 void byteReverse( unsigned char *buf, Q_UINT32 len );
00721
00722 Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
00723 Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00724 Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00725 Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
00726 void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00727 Q_UINT32 s );
00728 void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00729 Q_UINT32 s );
00730 void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
00731 Q_UINT32 s );
00732
00733 private:
00734 Q_UINT32 m_state[4];
00735 Q_UINT32 m_count[2];
00736 Q_UINT8 m_buffer[64];
00737 Digest m_digest;
00738 bool m_finalized;
00739
00740 class KMD4Private;
00741 KMD4Private* d;
00742 };
00743
00744
00745 #endif