KDECore
kcodecs.h
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> 00003 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU Lesser General Public License (LGPL) 00007 version 2 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 00018 RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. // krazy:exclude=copyright 00019 RSA Data Security, Inc. Created 1991. All rights reserved. 00020 00021 The KMD5 class is based on a C++ implementation of 00022 "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by 00023 Mordechai T. Abzug, Copyright (c) 1995. This implementation // krazy:exclude=copyright 00024 passes the test-suite as defined in RFC 1321. 00025 00026 The encoding and decoding utilities in KCodecs with the exception of 00027 quoted-printable are based on the java implementation in HTTPClient 00028 package by Ronald Tschalär Copyright (C) 1996-1999. // krazy:exclude=copyright 00029 00030 The quoted-printable codec as described in RFC 2045, section 6.7. is by 00031 Rik Hemsley (C) 2001. 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 (); //krazy:exclude=constref (simple array) 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
KDE 4.6 API Reference