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 }
00271
00272 class KMD5Private;
00318 class KDECORE_EXPORT KMD5
00319 {
00320 public:
00321
00322 typedef unsigned char Digest[16];
00323
00324 KMD5();
00325 ~KMD5();
00326
00335 explicit KMD5(const char* in, int len = -1);
00336
00342 explicit KMD5(const QByteArray& a );
00343
00352 void update(const char* in, int len = -1);
00353
00357 void update(const unsigned char* in, int len = -1);
00358
00364 void update(const QByteArray& in );
00365
00377 bool update(QIODevice& file);
00378
00384 void reset();
00385
00389 const Digest& rawDigest ();
00390
00400 void rawDigest( KMD5::Digest& bin );
00401
00406 QByteArray hexDigest ();
00407
00411 void hexDigest(QByteArray&);
00412
00417 QByteArray base64Digest ();
00418
00423 bool verify( const KMD5::Digest& digest);
00424
00428 bool verify(const QByteArray&);
00429
00430 protected:
00435 void transform( const unsigned char buffer[64] );
00436
00440 void finalize();
00441
00442 private:
00443 KMD5(const KMD5& u);
00444 KMD5& operator=(const KMD5& md);
00445
00446 void init();
00447 void encode( unsigned char* output, quint32 *in, quint32 len );
00448 void decode( quint32 *output, const unsigned char* in, quint32 len );
00449
00450 quint32 rotate_left( quint32 x, quint32 n );
00451 quint32 F( quint32 x, quint32 y, quint32 z );
00452 quint32 G( quint32 x, quint32 y, quint32 z );
00453 quint32 H( quint32 x, quint32 y, quint32 z );
00454 quint32 I( quint32 x, quint32 y, quint32 z );
00455 void FF( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00456 quint32 s, quint32 ac );
00457 void GG( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00458 quint32 s, quint32 ac );
00459 void HH( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00460 quint32 s, quint32 ac );
00461 void II( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00462 quint32 s, quint32 ac );
00463
00464 private:
00465 quint32 m_state[4];
00466 quint32 m_count[2];
00467 quint8 m_buffer[64];
00468 Digest m_digest;
00469 bool m_finalized;
00470
00471 KMD5Private* d;
00472 };
00473
00474
00475 #endif // KCODECS_H