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 QBase64 QCodecs
00038
00039 #include "mythbaseexp.h"
00040
00041 class QByteArray;
00042 class QIODevice;
00043
00074 namespace QCodecs
00075 {
00085 MBASE_PUBLIC QByteArray quotedPrintableEncode(const QByteArray & in,
00086 bool useCRLF = true);
00087
00106 MBASE_PUBLIC void quotedPrintableEncode(const QByteArray & in, QByteArray& out,
00107 bool useCRLF);
00108
00117 MBASE_PUBLIC QByteArray quotedPrintableDecode(const QByteArray & in);
00118
00136 MBASE_PUBLIC void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
00137
00138
00150 MBASE_PUBLIC QByteArray uuencode( const QByteArray& in );
00151
00167 MBASE_PUBLIC void uuencode( const QByteArray& in, QByteArray& out );
00168
00179 MBASE_PUBLIC QByteArray uudecode( const QByteArray& in );
00180
00200 MBASE_PUBLIC void uudecode( const QByteArray& in, QByteArray& out );
00201
00202
00216 MBASE_PUBLIC QByteArray base64Encode( const QByteArray& in, bool insertLFs = false);
00217
00239 MBASE_PUBLIC void base64Encode( const QByteArray& in, QByteArray& out,
00240 bool insertLFs = false );
00241
00249 MBASE_PUBLIC QByteArray base64Decode( const QByteArray& in );
00250
00268 MBASE_PUBLIC void base64Decode( const QByteArray& in, QByteArray& out );
00269
00270 }
00271
00272 class QMD5Private;
00318 class MBASE_PUBLIC QMD5
00319 {
00320 public:
00321
00322 typedef unsigned char Digest[16];
00323
00324 QMD5();
00325 ~QMD5();
00326
00335 explicit QMD5(const char* in, int len = -1);
00336
00342 explicit QMD5(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( QMD5::Digest& bin );
00401
00406 QByteArray hexDigest ();
00407
00411 void hexDigest(QByteArray&);
00412
00417 QByteArray base64Digest ();
00418
00423 bool verify( const QMD5::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 QMD5(const QMD5& u);
00444 QMD5& operator=(const QMD5& 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 static quint32 rotate_left( quint32 x, quint32 n );
00451 static quint32 F( quint32 x, quint32 y, quint32 z );
00452 static quint32 G( quint32 x, quint32 y, quint32 z );
00453 static quint32 H( quint32 x, quint32 y, quint32 z );
00454 static quint32 I( quint32 x, quint32 y, quint32 z );
00455 static void FF( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00456 quint32 s, quint32 ac );
00457 static void GG( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00458 quint32 s, quint32 ac );
00459 static void HH( quint32& a, quint32 b, quint32 c, quint32 d, quint32 x,
00460 quint32 s, quint32 ac );
00461 static 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 QMD5Private* d;
00472 };
00473
00474
00475 #endif // KCODECS_H