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 KCODECS_H
00035 #define KCODECS_H
00036
00037 #define KBase64 KCodecs
00038
00039 #include <kdecore_export.h>
00040
00041 class QByteArray;
00042 class QIODevice;
00043
00074 namespace KCodecs
00075 {
00085 KDECORE_EXPORT QByteArray quotedPrintableEncode(const QByteArray & in,
00086 bool useCRLF = true);
00087
00106 KDECORE_EXPORT void quotedPrintableEncode(const QByteArray & in, QByteArray& out,
00107 bool useCRLF);
00108
00117 KDECORE_EXPORT QByteArray quotedPrintableDecode(const QByteArray & in);
00118
00136 KDECORE_EXPORT void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
00137
00138
00150 KDECORE_EXPORT QByteArray uuencode( const QByteArray& in );
00151
00167 KDECORE_EXPORT void uuencode( const QByteArray& in, QByteArray& out );
00168
00179 KDECORE_EXPORT QByteArray uudecode( const QByteArray& in );
00180
00200 KDECORE_EXPORT void uudecode( const QByteArray& in, QByteArray& out );
00201
00202
00216 KDECORE_EXPORT QByteArray base64Encode( const QByteArray& in, bool insertLFs = false);
00217
00239 KDECORE_EXPORT void base64Encode( const QByteArray& in, QByteArray& out,
00240 bool insertLFs = false );
00241
00249 KDECORE_EXPORT QByteArray base64Decode( const QByteArray& in );
00250
00268 KDECORE_EXPORT void base64Decode( const QByteArray& in, QByteArray& out );
00269
00270
00280 KDECORE_EXPORT QString decodeRFC2047String(const QString &text);
00281
00282
00283 }
00284
00285 class KMD5Private;
00331 class KDECORE_EXPORT KMD5
00332 {
00333 public:
00334
00335 typedef unsigned char Digest[16];
00336
00337 KMD5();
00338 ~KMD5();
00339
00348 explicit KMD5(const char* in, int len = -1);
00349
00355 explicit KMD5(const QByteArray& a );
00356
00365 void update(const char* in, int len = -1);
00366
00370 void update(const unsigned char* in, int len = -1);
00371
00377 void update(const QByteArray& in );
00378
00390 bool update(QIODevice& file);
00391
00397 void reset();
00398
00402 const Digest& rawDigest ();
00403
00413 void rawDigest( KMD5::Digest& bin );
00414
00419 QByteArray hexDigest ();
00420
00424 void hexDigest(QByteArray&);
00425
00430 QByteArray base64Digest ();
00431
00436 bool verify( const KMD5::Digest& digest);
00437
00441 bool verify(const QByteArray&);
00442
00443 protected:
00448 void transform( const unsigned char buffer[64] );
00449
00453 void finalize();
00454
00455 private:
00456 KMD5(const KMD5& u);
00457 KMD5& operator=(const KMD5& md);
00458
00459 void init();
00460 void encode( unsigned char* output, quint32 *in, quint32 len );
00461 void decode( quint32 *output, const unsigned char* in, quint32 len );
00462
00463 quint32 rotate_left( quint32 x, quint32 n );
00464 quint32 F( quint32 x, quint32 y, quint32 z );
00465 quint32 G( quint32 x, quint32 y, quint32 z );
00466 quint32 H( quint32 x, quint32 y, quint32 z );
00467 quint32 I( quint32 x, quint32 y, quint32 z );
00468 void FF( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00469 quint32 s, quint32 ac );
00470 void GG( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00471 quint32 s, quint32 ac );
00472 void HH( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00473 quint32 s, quint32 ac );
00474 void II( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00475 quint32 s, quint32 ac );
00476
00477 private:
00478 quint32 m_state[4];
00479 quint32 m_count[2];
00480 quint8 m_buffer[64];
00481 Digest m_digest;
00482 bool m_finalized;
00483
00484 KMD5Private* d;
00485 };
00486
00487
00488 #endif // KCODECS_H