kmdcodec.h
来自「将konqueror浏览器移植到ARM9 2410中」· C头文件 代码 · 共 737 行 · 第 1/2 页
H
737 行
/* Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. This KMD5 class is based on a C++ implementation of "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by Mordechai T. Abzug, Copyright (c) 1995. This implementation passes the test-suite as defined by RFC 1321. RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. RSA Data Security, Inc. Created 1991. All rights reserved. The encoding and decoding utilities in KCodecs with the exception of quoted-printable were ported from the HTTPClient java package by Ronald Tschal鋜 Copyright (C) 1996-1999. The quoted-printable codec as described in RFC 2045, section 6.7. is by Rik Hemsley (C) 2001.*/#ifndef _KMDBASE_H#define _KMDBASE_H#define KBase64 KCodecs#include <stdio.h>#include <qglobal.h>#include <qstring.h>typedef char HASH[16];typedef char HASHHEX[33];/** * A wrapper class for the most commonly used encoding and * decoding algorithms. Currently there is support for encoding * and decoding input using base64, uu and the quoted-printable * specifications. * * @sect Useage: * * The convienence functions are well suited for encoding * and decoding a relatively small input. * * <PRE> * QCString input = "Aladdin:open sesame"; * QCString result = KCodecs::base64Encode(input); * printf ("Result: %c", result.data()); * * Output should be * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ== * </PRE> * * @short A collection of commonly used encoding and decoding algorithms. * @author Dawit Alemayehu <adawit@kde.org> * @author Rik Hemsley <rik@kde.org> */class KCodecs{public: /** * Encodes the given data using the quoted-printable algorithm. * Equivalent to quotedPrintableEncode(in, true). * * @param in data to be encoded. * @return quoted-printable encoded data. */ static QCString quotedPrintableEncode(const QByteArray & in); /** * Encodes the given data using the quoted-printable algorithm. * * @param in data to be encoded. * @param useCRLF if true the input data is expected to have * CRLF line breaks and the output will have CRLF line breaks, too. * @return quoted-printable encoded data. */ static QCString quotedPrintableEncode(const QByteArray & in, bool useCRLF); /** * Decodes a quoted-printable encoded string. * Accepts data with CRLF or standard unix line breaks * * @param in the data to be decoded. * @return decoded data. */ static QByteArray quotedPrintableDecode(const QCString & in); /** * Encodes the given data using the uuencode algorithm. * * The output is split into lines starting with the number of * encoded octets in the line and ending with a newline. No * line is longer than 45 octets (60 characters), excluding the * line terminator. * * @param in the data to be uuencoded * @return a uuencoded data. */ static QCString uuencode( const QByteArray& in ); /** * Encodes the given data using the uuencode algorithm. * * Use this function if you want the result of the encoding * to be placed in another array and cut down the number of * copy opertation that have to be performed in the process. * * <u>NOTE:</u> the output array is always first reset for * sanity and then resized appropriatly. Hence, any data * that is present in the output array will be lost. * * @param in the data to be uuencoded. * @param out the container for the uudecoded data. */ static void uuencode( const QByteArray& in, QByteArray& out ); /** * Encodes the given string using the uuencode algorithm. * * @param str the string to be uuencoded. * @return a uuencoded string. */ static QCString uuencode( const QCString& str ); /** * Decodes the given data using the uuencode algorithm. * * Any 'begin' and 'end' lines liks those generated by * *nix utilities will automatically be ignored. * * @param in the data uuencoded data to be decoded. * @return the decoded data. */ static QCString uudecode( const QByteArray& in ); /** * Decodes the given data using the uudecode algorithm. * * Use this function if you want the result of the decoding * to be placed in another array and cut down the number of * copy opertation that have to be performed in the process. * * Any 'begin' and 'end' lines liks those generated by * *nix utilities will automatically be ignored. * * <u>IMPORTANT:</u> the output array is first reset and then * resized appropriately. Hence, any data that is present in * the output array will be lost. * * @param in the uuencoded-data to be decoded. * @param out the container for the uudecoded data. */ static void uudecode( const QByteArray& in, QByteArray& out ); /** * Decodes a uuencoded string. * * @param str the string to be decoded. * @return a uudecoded string. */ static QCString uudecode( const QCString& str ); /** * Encodes the given data using the base64 algorithm. * * The boolean argument determines if the encoded data is * going to be restricted to 76 characters or less per line * as specified by RFC 2045. If @p insertLFs is true, then * there will be 76 characters or less per line. * * @param in the data to be encoded. * @param insertLFs limit the number of characters per line. * @return a base64 encoded data. */ static QCString base64Encode( const QByteArray& in, bool insertLFs ); /** * @deprecated. * * Use @ref base64Encode(const QByteArray&, bool) * with the boolean argument set to false. */ // BC: Merge in KDE 3.x with the above function by // defaulting boolean argument to false. static QCString base64Encode( const QByteArray& in ); /** * Encodes the given data using the base64 algorithm. * * Use this function whenever you are dealing with very * large data or a stream of data. The boolean argument * determines if the encoded data is going to be restricted * to 76 characters or less per line as specified by RFC 2045. * If @p insertLFs is true, then there will be 76 characters or * less per line. * * <u>NOTE:</u> the output array is always first reset for * sanity and then resized appropriatly. Hence, any data * that is present in the output array will be lost. * * @param in the data to be encoded using base64. * @param insertLFs limit the number of characters per line. * @param out the container for the encoded data. */ static void base64Encode( const QByteArray& in, QByteArray& out, bool insertLFs ); /** * @deprecated. * * Use @ref base64Encode(const QByteArray&, QByteArray&, bool) * with the boolean argument set to false. */ // BC: Merge in KDE 3.x with the above function by // defaulting boolean argument to false. static void base64Encode( const QByteArray& in, QByteArray& out ); /** * Encodes the given string using the base64 algorithm. * * The boolean argument determines if the encoded data is * going to be restricted to 76 characters or less per line * as specified by RFC 2045. If @p insertLFs is true, then * there will be 76 characters or less per line. * * @param str the string to be encoded. * @param insertLFs limit the number of characters per line. * @return the decoded string. */ static QCString base64Encode( const QCString& str, bool insertLFs ); /** * @deprecated. * * Use @ref base64Encode(const QCString&, bool) * with the boolean argument set to false. */ // BC: Merge in KDE 3.x with the above function by // defaulting boolean argument to false. static QCString base64Encode( const QCString& str ); /** * Decodes the given data that was encoded using the * base64 algorithm. * * @param in the base64-encoded data to be decoded. * @return the decoded data. */ static QCString base64Decode( const QByteArray& in ); /** * Decodes the given data that was encoded with the base64 * algorithm. * * Use this function if you want the result of the decoding * to be placed in another array and cut down the number of * copy opertation that have to be performed in the process. * * <u>IMPORTANT:</u> the output array is first reset and then * resized appropriately. Hence, any data that is present in * the output array will be lost. * * @param in the encoded data to be decoded. * @param out the container for the decoded data. */ static void base64Decode( const QByteArray& in, QByteArray& out ); /** * Decodes a string encoded with the base64 algorithm. * * @param str the base64-encoded string. * @return the decoded string. */ static QCString base64Decode( const QCString& str ); /** * Encodes the QString data using the base64 algorithm. * * <u>NOTE:</u> This function is ONLY provided for convenience * and backward compatability! Using it can result in an incorrectly * encoded data since the conversion of the QString input to latin-1 * can and will result in data loss if the input data contains non- * latin1 characters. As such it is highly recommended that you avoid * this function unless you are absolutely certain that your input * does not contain any non-latin1 character!! */ static QString base64Encode( const QString& str ); /** * Decodes the encoded QString data using the base64 algorithm. * * <u>NOTE:</u> This function is ONLY provided for convenience * and backward compatability! Using it can result in an incorrectly * decoded data since the conversion of the QString input to latin-1 * can and will result in data loss if the input data contains non- * latin1 characters. As such it is highly recommended that you avoid * this function unless you are absolutely certain that your input * does not contain any non-latin1 character!! */ static QString base64Decode( const QString& str ); /** * Encodes the QString data using the uuencode algorithm. * * <u>NOTE:</u> This function is ONLY provided for convenience * and backward compatability! Using it can result in an incorrectly * encoded data since the conversion of the QString input to latin-1 * can and will result in data loss if the input data contains non- * latin1 characters. As such it is highly recommended that you avoid * this function unless you are absolutely certain that your input * does not contain any non-latin1 character!! */ static QString uuencode( const QString& str ); /** * Decodes the QString data using the uuencode algorithm. * * <u>NOTE:</u> This function is ONLY provided for convenience * and backward compatability! Using it can result in an incorrectly * decoded data since the conversion of the QString input to latin-1 * can and will result in data loss if the input data contains non- * latin1 characters. As such it is highly recommended that you avoid * this function unless you are absolutely certain that your input * does not contain any non-latin1 character!! */ static QString uudecode( const QString& str ); /** * @deprecated. Use @ref base64Encode(const QString&) instead. */ static QString encodeString( const QString& data ); /** * @deprecated. Use @ref base64Decode(const QString&) instead. */ static QString decodeString( const QString& data );private: KCodecs();private: static char UUEncMap[64]; static char UUDecMap[128]; static char Base64EncMap[64]; static char Base64DecMap[128]; static char hexChars[16]; static const unsigned int maxQPLineLength;};/** * Provides an easy to use C++ implementation of RSA's * MD5 algorithm. * * The default constructor is designed to provide much the same * functionality as the most commonly used C-implementation while * the other three constructors are meant to further simplify the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?