-rw-r--r-- | microkde/kdecore/kmdcodec.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/microkde/kdecore/kmdcodec.h b/microkde/kdecore/kmdcodec.h index 2c4d611..616b683 100644 --- a/microkde/kdecore/kmdcodec.h +++ b/microkde/kdecore/kmdcodec.h | |||
@@ -10,345 +10,347 @@ | |||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public | 14 | You should have received a copy of the GNU Library General Public |
15 | License along with this program; if not, write to the Free Software | 15 | License along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | 17 | ||
18 | RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. | 18 | RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. |
19 | RSA Data Security, Inc. Created 1991. All rights reserved. | 19 | RSA Data Security, Inc. Created 1991. All rights reserved. |
20 | 20 | ||
21 | The KMD5 class is based on a C++ implementation of | 21 | The KMD5 class is based on a C++ implementation of |
22 | "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by | 22 | "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by |
23 | Mordechai T. Abzug,Copyright (c) 1995. This implementation | 23 | Mordechai T. Abzug,Copyright (c) 1995. This implementation |
24 | passes the test-suite as defined in RFC 1321. | 24 | passes the test-suite as defined in RFC 1321. |
25 | 25 | ||
26 | The encoding and decoding utilities in KCodecs with the exception of | 26 | The encoding and decoding utilities in KCodecs with the exception of |
27 | quoted-printable are based on the java implementation in HTTPClient | 27 | quoted-printable are based on the java implementation in HTTPClient |
28 | package by Ronald Tschalär Copyright (C) 1996-1999. | 28 | package by Ronald Tschalär Copyright (C) 1996-1999. |
29 | 29 | ||
30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by | 30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by |
31 | Rik Hemsley (C) 2001. | 31 | Rik Hemsley (C) 2001. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef _KMDBASE_H | 34 | #ifndef _KMDBASE_H |
35 | #define _KMDBASE_H | 35 | #define _KMDBASE_H |
36 | 36 | ||
37 | #define KBase64 KCodecs | 37 | #define KBase64 KCodecs |
38 | 38 | ||
39 | #include <qglobal.h> | 39 | #include <qglobal.h> |
40 | #include <qstring.h> | 40 | #include <qstring.h> |
41 | #include <qiodevice.h> | 41 | #include <qiodevice.h> |
42 | //Added by qt3to4: | ||
43 | #include <Q3CString> | ||
42 | 44 | ||
43 | /** | 45 | /** |
44 | * A wrapper class for the most commonly used encoding and | 46 | * A wrapper class for the most commonly used encoding and |
45 | * decoding algorithms. Currently there is support for encoding | 47 | * decoding algorithms. Currently there is support for encoding |
46 | * and decoding input using base64, uu and the quoted-printable | 48 | * and decoding input using base64, uu and the quoted-printable |
47 | * specifications. | 49 | * specifications. |
48 | * | 50 | * |
49 | * @sect Usage: | 51 | * @sect Usage: |
50 | * | 52 | * |
51 | * <PRE> | 53 | * <PRE> |
52 | * QCString input = "Aladdin:open sesame"; | 54 | * QCString input = "Aladdin:open sesame"; |
53 | * QCString result = KCodecs::base64Encode(input); | 55 | * QCString result = KCodecs::base64Encode(input); |
54 | * cout << "Result: " << result.data() << endl; | 56 | * cout << "Result: " << result.data() << endl; |
55 | * | 57 | * |
56 | * Output should be | 58 | * Output should be |
57 | * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ== | 59 | * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ== |
58 | * </PRE> | 60 | * </PRE> |
59 | * | 61 | * |
60 | * The above example makes use of the convenience functions | 62 | * The above example makes use of the convenience functions |
61 | * (ones that accept/return null-terminated strings) to encode/decode | 63 | * (ones that accept/return null-terminated strings) to encode/decode |
62 | * a string. If what you need is to encode or decode binary data, then | 64 | * a string. If what you need is to encode or decode binary data, then |
63 | * it is highly recommended that you use the functions that take an input | 65 | * it is highly recommended that you use the functions that take an input |
64 | * and output QByteArray as arguments. These functions are specifically | 66 | * and output QByteArray as arguments. These functions are specifically |
65 | * tailored for encoding and decoding binary data. | 67 | * tailored for encoding and decoding binary data. |
66 | * | 68 | * |
67 | * @short A collection of commonly used encoding and decoding algorithms. | 69 | * @short A collection of commonly used encoding and decoding algorithms. |
68 | * @author Dawit Alemayehu <adawit@kde.org> | 70 | * @author Dawit Alemayehu <adawit@kde.org> |
69 | * @author Rik Hemsley <rik@kde.org> | 71 | * @author Rik Hemsley <rik@kde.org> |
70 | */ | 72 | */ |
71 | class KCodecs | 73 | class KCodecs |
72 | { | 74 | { |
73 | public: | 75 | public: |
74 | 76 | ||
75 | /** | 77 | /** |
76 | * Encodes the given data using the quoted-printable algorithm. | 78 | * Encodes the given data using the quoted-printable algorithm. |
77 | * | 79 | * |
78 | * @param in data to be encoded. | 80 | * @param in data to be encoded. |
79 | * @param useCRLF if true the input data is expected to have | 81 | * @param useCRLF if true the input data is expected to have |
80 | * CRLF line breaks and the output will have CRLF line | 82 | * CRLF line breaks and the output will have CRLF line |
81 | * breaks, too. | 83 | * breaks, too. |
82 | * @return quoted-printable encoded data. | 84 | * @return quoted-printable encoded data. |
83 | */ | 85 | */ |
84 | static QCString quotedPrintableEncode(const QByteArray & in, | 86 | static Q3CString quotedPrintableEncode(const QByteArray & in, |
85 | bool useCRLF = true); | 87 | bool useCRLF = true); |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * @overload | 90 | * @overload |
89 | * | 91 | * |
90 | * Same as above except it accepts a null terminated | 92 | * Same as above except it accepts a null terminated |
91 | * string instead an array. | 93 | * string instead an array. |
92 | * | 94 | * |
93 | * @param str data to be encoded. | 95 | * @param str data to be encoded. |
94 | * @param useCRLF if true the input data is expected to have | 96 | * @param useCRLF if true the input data is expected to have |
95 | * CRLF line breaks and the output will have CRLF line | 97 | * CRLF line breaks and the output will have CRLF line |
96 | * breaks, too. | 98 | * breaks, too. |
97 | * @return quoted-printable encoded data. | 99 | * @return quoted-printable encoded data. |
98 | */ | 100 | */ |
99 | static QCString quotedPrintableEncode(const QCString & str, | 101 | static Q3CString quotedPrintableEncode(const Q3CString & str, |
100 | bool useCRLF = true); | 102 | bool useCRLF = true); |
101 | 103 | ||
102 | /** | 104 | /** |
103 | * Encodes the given data using the quoted-printable algorithm. | 105 | * Encodes the given data using the quoted-printable algorithm. |
104 | * | 106 | * |
105 | * Use this function if you want the result of the encoding | 107 | * Use this function if you want the result of the encoding |
106 | * to be placed in another array which cuts down the number | 108 | * to be placed in another array which cuts down the number |
107 | * of copy operation that have to be performed in the process. | 109 | * of copy operation that have to be performed in the process. |
108 | * This is also the preferred method for encoding binary data. | 110 | * This is also the preferred method for encoding binary data. |
109 | * | 111 | * |
110 | * NOTE: the output array is first reset and then resized | 112 | * NOTE: the output array is first reset and then resized |
111 | * appropriately before use, hence, all data stored in the | 113 | * appropriately before use, hence, all data stored in the |
112 | * output array will be lost. | 114 | * output array will be lost. |
113 | * | 115 | * |
114 | * @param in data to be encoded. | 116 | * @param in data to be encoded. |
115 | * @param out decoded data. | 117 | * @param out decoded data. |
116 | * @param useCRLF if true the input data is expected to have | 118 | * @param useCRLF if true the input data is expected to have |
117 | * CRLF line breaks and the output will have CRLF line | 119 | * CRLF line breaks and the output will have CRLF line |
118 | * breaks, too. | 120 | * breaks, too. |
119 | * @return quoted-printable encoded data. | 121 | * @return quoted-printable encoded data. |
120 | */ | 122 | */ |
121 | static void quotedPrintableEncode(const QByteArray & in, QByteArray& out, | 123 | static void quotedPrintableEncode(const QByteArray & in, QByteArray& out, |
122 | bool useCRLF); | 124 | bool useCRLF); |
123 | 125 | ||
124 | /** | 126 | /** |
125 | * Decodes a quoted-printable encoded string. | 127 | * Decodes a quoted-printable encoded string. |
126 | * | 128 | * |
127 | * Accepts data with CRLF or standard unix line breaks. | 129 | * Accepts data with CRLF or standard unix line breaks. |
128 | * | 130 | * |
129 | * @param in the data to be decoded. | 131 | * @param in the data to be decoded. |
130 | * @return decoded data. | 132 | * @return decoded data. |
131 | */ | 133 | */ |
132 | static QCString quotedPrintableDecode(const QByteArray & in); | 134 | static Q3CString quotedPrintableDecode(const QByteArray & in); |
133 | 135 | ||
134 | /** | 136 | /** |
135 | * @overload | 137 | * @overload |
136 | * | 138 | * |
137 | * Same as above except it accepts a null terminated | 139 | * Same as above except it accepts a null terminated |
138 | * string instead an array. | 140 | * string instead an array. |
139 | * | 141 | * |
140 | * @param str the data to be decoded. | 142 | * @param str the data to be decoded. |
141 | * @return decoded data. | 143 | * @return decoded data. |
142 | */ | 144 | */ |
143 | static QCString quotedPrintableDecode(const QCString & str); | 145 | static Q3CString quotedPrintableDecode(const Q3CString & str); |
144 | 146 | ||
145 | /** | 147 | /** |
146 | * Decodes a quoted-printable encoded data. | 148 | * Decodes a quoted-printable encoded data. |
147 | * | 149 | * |
148 | * Accepts data with CRLF or standard unix line breaks. | 150 | * Accepts data with CRLF or standard unix line breaks. |
149 | * Use this function if you want the result of the decoding | 151 | * Use this function if you want the result of the decoding |
150 | * to be placed in another array which cuts down the number | 152 | * to be placed in another array which cuts down the number |
151 | * of copy operation that have to be performed in the process. | 153 | * of copy operation that have to be performed in the process. |
152 | * This is also the preferred method for decoding an encoded | 154 | * This is also the preferred method for decoding an encoded |
153 | * binary data. | 155 | * binary data. |
154 | * | 156 | * |
155 | * NOTE: the output array is first reset and then resized | 157 | * NOTE: the output array is first reset and then resized |
156 | * appropriately before use, hence, all data stored in the | 158 | * appropriately before use, hence, all data stored in the |
157 | * output array will be lost. | 159 | * output array will be lost. |
158 | * | 160 | * |
159 | * @param in data to be encoded. | 161 | * @param in data to be encoded. |
160 | * @param out decoded data. | 162 | * @param out decoded data. |
161 | * | 163 | * |
162 | * @return quoted-printable encoded data. | 164 | * @return quoted-printable encoded data. |
163 | */ | 165 | */ |
164 | static void quotedPrintableDecode(const QByteArray & in, QByteArray& out); | 166 | static void quotedPrintableDecode(const QByteArray & in, QByteArray& out); |
165 | 167 | ||
166 | 168 | ||
167 | /** | 169 | /** |
168 | * Encodes the given data using the uuencode algorithm. | 170 | * Encodes the given data using the uuencode algorithm. |
169 | * | 171 | * |
170 | * The output is split into lines starting with the number of | 172 | * The output is split into lines starting with the number of |
171 | * encoded octets in the line and ending with a newline. No | 173 | * encoded octets in the line and ending with a newline. No |
172 | * line is longer than 45 octets (60 characters), excluding the | 174 | * line is longer than 45 octets (60 characters), excluding the |
173 | * line terminator. | 175 | * line terminator. |
174 | * | 176 | * |
175 | * @param in the data to be uuencoded | 177 | * @param in the data to be uuencoded |
176 | * @return a uuencoded data. | 178 | * @return a uuencoded data. |
177 | */ | 179 | */ |
178 | static QCString uuencode( const QByteArray& in ); | 180 | static Q3CString uuencode( const QByteArray& in ); |
179 | 181 | ||
180 | /** | 182 | /** |
181 | * @overload | 183 | * @overload |
182 | * | 184 | * |
183 | * Same as the above functions except it accepts | 185 | * Same as the above functions except it accepts |
184 | * a null terminated string instead an array. | 186 | * a null terminated string instead an array. |
185 | * | 187 | * |
186 | * @param str the string to be uuencoded. | 188 | * @param str the string to be uuencoded. |
187 | * @return the encoded string. | 189 | * @return the encoded string. |
188 | */ | 190 | */ |
189 | static QCString uuencode( const QCString& str ); | 191 | static Q3CString uuencode( const Q3CString& str ); |
190 | 192 | ||
191 | /** | 193 | /** |
192 | * Encodes the given data using the uuencode algorithm. | 194 | * Encodes the given data using the uuencode algorithm. |
193 | * | 195 | * |
194 | * Use this function if you want the result of the encoding | 196 | * Use this function if you want the result of the encoding |
195 | * to be placed in another array and cut down the number of | 197 | * to be placed in another array and cut down the number of |
196 | * copy operation that have to be performed in the process. | 198 | * copy operation that have to be performed in the process. |
197 | * This is the preffered method for encoding binary data. | 199 | * This is the preffered method for encoding binary data. |
198 | * | 200 | * |
199 | * NOTE: the output array is first reset and then resized | 201 | * NOTE: the output array is first reset and then resized |
200 | * appropriately before use, hence, all data stored in the | 202 | * appropriately before use, hence, all data stored in the |
201 | * output array will be lost. | 203 | * output array will be lost. |
202 | * | 204 | * |
203 | * @param in the data to be uuencoded. | 205 | * @param in the data to be uuencoded. |
204 | * @param out the container for the uudecoded data. | 206 | * @param out the container for the uudecoded data. |
205 | */ | 207 | */ |
206 | static void uuencode( const QByteArray& in, QByteArray& out ); | 208 | static void uuencode( const QByteArray& in, QByteArray& out ); |
207 | 209 | ||
208 | /** | 210 | /** |
209 | * Decodes the given data using the uuencode algorithm. | 211 | * Decodes the given data using the uuencode algorithm. |
210 | * | 212 | * |
211 | * Any 'begin' and 'end' lines like those generated by | 213 | * Any 'begin' and 'end' lines like those generated by |
212 | * the utilities in unix and unix-like OS will be | 214 | * the utilities in unix and unix-like OS will be |
213 | * automatically ignored. | 215 | * automatically ignored. |
214 | * | 216 | * |
215 | * @param in the data uuencoded data to be decoded. | 217 | * @param in the data uuencoded data to be decoded. |
216 | * @return a decoded string. | 218 | * @return a decoded string. |
217 | */ | 219 | */ |
218 | static QCString uudecode( const QByteArray& in ); | 220 | static Q3CString uudecode( const QByteArray& in ); |
219 | 221 | ||
220 | /** | 222 | /** |
221 | * @overload | 223 | * @overload |
222 | * | 224 | * |
223 | * Same as the above functions except it accepts | 225 | * Same as the above functions except it accepts |
224 | * a null terminated string instead an array. | 226 | * a null terminated string instead an array. |
225 | * | 227 | * |
226 | * @param str the string to be decoded. | 228 | * @param str the string to be decoded. |
227 | * @return a uudecoded string. | 229 | * @return a uudecoded string. |
228 | */ | 230 | */ |
229 | static QCString uudecode( const QCString& str ); | 231 | static Q3CString uudecode( const Q3CString& str ); |
230 | 232 | ||
231 | /** | 233 | /** |
232 | * Decodes the given data using the uudecode algorithm. | 234 | * Decodes the given data using the uudecode algorithm. |
233 | * | 235 | * |
234 | * Use this function if you want the result of the decoding | 236 | * Use this function if you want the result of the decoding |
235 | * to be placed in another array which cuts down the number | 237 | * to be placed in another array which cuts down the number |
236 | * of copy operation that have to be performed in the process. | 238 | * of copy operation that have to be performed in the process. |
237 | * This is the preferred method for decoding binary data. | 239 | * This is the preferred method for decoding binary data. |
238 | * | 240 | * |
239 | * Any 'begin' and 'end' lines like those generated by | 241 | * Any 'begin' and 'end' lines like those generated by |
240 | * the utilities in unix and unix-like OS will be | 242 | * the utilities in unix and unix-like OS will be |
241 | * automatically ignored. | 243 | * automatically ignored. |
242 | * | 244 | * |
243 | * NOTE: the output array is first reset and then resized | 245 | * NOTE: the output array is first reset and then resized |
244 | * appropriately before use, hence, all data stored in the | 246 | * appropriately before use, hence, all data stored in the |
245 | * output array will be lost. | 247 | * output array will be lost. |
246 | * | 248 | * |
247 | * @param in the uuencoded-data to be decoded. | 249 | * @param in the uuencoded-data to be decoded. |
248 | * @param out the container for the uudecoded data. | 250 | * @param out the container for the uudecoded data. |
249 | */ | 251 | */ |
250 | static void uudecode( const QByteArray& in, QByteArray& out ); | 252 | static void uudecode( const QByteArray& in, QByteArray& out ); |
251 | 253 | ||
252 | 254 | ||
253 | /** | 255 | /** |
254 | * Encodes the given data using the base64 algorithm. | 256 | * Encodes the given data using the base64 algorithm. |
255 | * | 257 | * |
256 | * The boolean argument determines if the encoded data is | 258 | * The boolean argument determines if the encoded data is |
257 | * going to be restricted to 76 characters or less per line | 259 | * going to be restricted to 76 characters or less per line |
258 | * as specified by RFC 2045. If @p insertLFs is true, then | 260 | * as specified by RFC 2045. If @p insertLFs is true, then |
259 | * there will be 76 characters or less per line. | 261 | * there will be 76 characters or less per line. |
260 | * | 262 | * |
261 | * @param in the data to be encoded. | 263 | * @param in the data to be encoded. |
262 | * @param insertLFs limit the number of characters per line. | 264 | * @param insertLFs limit the number of characters per line. |
263 | * | 265 | * |
264 | * @return a base64 encoded string. | 266 | * @return a base64 encoded string. |
265 | */ | 267 | */ |
266 | static QCString base64Encode( const QByteArray& in, bool insertLFs = false); | 268 | static Q3CString base64Encode( const QByteArray& in, bool insertLFs = false); |
267 | 269 | ||
268 | /** | 270 | /** |
269 | * @overload | 271 | * @overload |
270 | * | 272 | * |
271 | * Same as the above functions except it accepts | 273 | * Same as the above functions except it accepts |
272 | * a null terminated string instead an array. | 274 | * a null terminated string instead an array. |
273 | * | 275 | * |
274 | * @param str the string to be encoded. | 276 | * @param str the string to be encoded. |
275 | * @param insertLFs limit the number of characters per line. | 277 | * @param insertLFs limit the number of characters per line. |
276 | * @return the decoded string. | 278 | * @return the decoded string. |
277 | */ | 279 | */ |
278 | static QCString base64Encode( const QCString& str, bool insertLFs = false ); | 280 | static Q3CString base64Encode( const Q3CString& str, bool insertLFs = false ); |
279 | 281 | ||
280 | /** | 282 | /** |
281 | * Encodes the given data using the base64 algorithm. | 283 | * Encodes the given data using the base64 algorithm. |
282 | * | 284 | * |
283 | * Use this function if you want the result of the encoding | 285 | * Use this function if you want the result of the encoding |
284 | * to be placed in another array which cuts down the number | 286 | * to be placed in another array which cuts down the number |
285 | * of copy operation that have to be performed in the process. | 287 | * of copy operation that have to be performed in the process. |
286 | * This is also the preferred method for encoding binary data. | 288 | * This is also the preferred method for encoding binary data. |
287 | * | 289 | * |
288 | * The boolean argument determines if the encoded data is going | 290 | * The boolean argument determines if the encoded data is going |
289 | * to be restricted to 76 characters or less per line as specified | 291 | * to be restricted to 76 characters or less per line as specified |
290 | * by RFC 2045. If @p insertLFs is true, then there will be 76 | 292 | * by RFC 2045. If @p insertLFs is true, then there will be 76 |
291 | * characters or less per line. | 293 | * characters or less per line. |
292 | * | 294 | * |
293 | * NOTE: the output array is first reset and then resized | 295 | * NOTE: the output array is first reset and then resized |
294 | * appropriately before use, hence, all data stored in the | 296 | * appropriately before use, hence, all data stored in the |
295 | * output array will be lost. | 297 | * output array will be lost. |
296 | * | 298 | * |
297 | * @param in the data to be encoded using base64. | 299 | * @param in the data to be encoded using base64. |
298 | * @param out the container for the encoded data. | 300 | * @param out the container for the encoded data. |
299 | * @param insertLFs limit the number of characters per line. | 301 | * @param insertLFs limit the number of characters per line. |
300 | */ | 302 | */ |
301 | static void base64Encode( const QByteArray& in, QByteArray& out, | 303 | static void base64Encode( const QByteArray& in, QByteArray& out, |
302 | bool insertLFs = false ); | 304 | bool insertLFs = false ); |
303 | 305 | ||
304 | /** | 306 | /** |
305 | * Decodes the given data that was encoded using the | 307 | * Decodes the given data that was encoded using the |
306 | * base64 algorithm. | 308 | * base64 algorithm. |
307 | * | 309 | * |
308 | * @param in the base64-encoded data to be decoded. | 310 | * @param in the base64-encoded data to be decoded. |
309 | * @return the decoded data. | 311 | * @return the decoded data. |
310 | */ | 312 | */ |
311 | static QCString base64Decode( const QByteArray& in ); | 313 | static Q3CString base64Decode( const QByteArray& in ); |
312 | 314 | ||
313 | /** | 315 | /** |
314 | * @overload | 316 | * @overload |
315 | * | 317 | * |
316 | * Same as the above functions except it accepts | 318 | * Same as the above functions except it accepts |
317 | * a null terminated string instead an array. | 319 | * a null terminated string instead an array. |
318 | * | 320 | * |
319 | * @param str the base64-encoded string. | 321 | * @param str the base64-encoded string. |
320 | * @return the decoded string. | 322 | * @return the decoded string. |
321 | */ | 323 | */ |
322 | static QCString base64Decode( const QCString& str ); | 324 | static Q3CString base64Decode( const Q3CString& str ); |
323 | 325 | ||
324 | /** | 326 | /** |
325 | * Decodes the given data that was encoded with the base64 | 327 | * Decodes the given data that was encoded with the base64 |
326 | * algorithm. | 328 | * algorithm. |
327 | * | 329 | * |
328 | * Use this function if you want the result of the decoding | 330 | * Use this function if you want the result of the decoding |
329 | * to be placed in another array which cuts down the number | 331 | * to be placed in another array which cuts down the number |
330 | * of copy operation that have to be performed in the process. | 332 | * of copy operation that have to be performed in the process. |
331 | * This is also the preferred method for decoding an encoded | 333 | * This is also the preferred method for decoding an encoded |
332 | * binary data. | 334 | * binary data. |
333 | * | 335 | * |
334 | * NOTE: the output array is first reset and then resized | 336 | * NOTE: the output array is first reset and then resized |
335 | * appropriately before use, hence, all data stored in the | 337 | * appropriately before use, hence, all data stored in the |
336 | * output array will be lost. | 338 | * output array will be lost. |
337 | * | 339 | * |
338 | * @param in the encoded data to be decoded. | 340 | * @param in the encoded data to be decoded. |
339 | * @param out the container for the decoded data. | 341 | * @param out the container for the decoded data. |
340 | */ | 342 | */ |
341 | static void base64Decode( const QByteArray& in, QByteArray& out ); | 343 | static void base64Decode( const QByteArray& in, QByteArray& out ); |
342 | 344 | ||
343 | 345 | ||
344 | private: | 346 | private: |
345 | KCodecs(); | 347 | KCodecs(); |
346 | 348 | ||
347 | private: | 349 | private: |
348 | static const char UUEncMap[64]; | 350 | static const char UUEncMap[64]; |
349 | static const char UUDecMap[128]; | 351 | static const char UUDecMap[128]; |
350 | static const char Base64EncMap[64]; | 352 | static const char Base64EncMap[64]; |
351 | static const char Base64DecMap[128]; | 353 | static const char Base64DecMap[128]; |
352 | static const char hexChars[16]; | 354 | static const char hexChars[16]; |
353 | static const unsigned int maxQPLineLength; | 355 | static const unsigned int maxQPLineLength; |
354 | }; | 356 | }; |
@@ -402,158 +404,158 @@ class KMD5Private; | |||
402 | */ | 404 | */ |
403 | 405 | ||
404 | class KMD5 | 406 | class KMD5 |
405 | { | 407 | { |
406 | public: | 408 | public: |
407 | 409 | ||
408 | typedef unsigned char Digest[16]; | 410 | typedef unsigned char Digest[16]; |
409 | 411 | ||
410 | KMD5(); | 412 | KMD5(); |
411 | 413 | ||
412 | /** | 414 | /** |
413 | * Constructor that updates the digest for the given string. | 415 | * Constructor that updates the digest for the given string. |
414 | * | 416 | * |
415 | * @param in C string or binary data | 417 | * @param in C string or binary data |
416 | * @param len if negative, calculates the length by using | 418 | * @param len if negative, calculates the length by using |
417 | * strlen on the first parameter, otherwise | 419 | * strlen on the first parameter, otherwise |
418 | * it trusts the given length (does not stop on NUL byte). | 420 | * it trusts the given length (does not stop on NUL byte). |
419 | */ | 421 | */ |
420 | KMD5(const char* in, int len = -1); | 422 | KMD5(const char* in, int len = -1); |
421 | 423 | ||
422 | /** | 424 | /** |
423 | * @overload | 425 | * @overload |
424 | * | 426 | * |
425 | * Same as above except it accepts a QByteArray as its argument. | 427 | * Same as above except it accepts a QByteArray as its argument. |
426 | */ | 428 | */ |
427 | KMD5(const QByteArray& a ); | 429 | KMD5(const QByteArray& a ); |
428 | 430 | ||
429 | /** | 431 | /** |
430 | * @overload | 432 | * @overload |
431 | * | 433 | * |
432 | * Same as above except it accepts a QByteArray as its argument. | 434 | * Same as above except it accepts a QByteArray as its argument. |
433 | */ | 435 | */ |
434 | KMD5(const QCString& a ); | 436 | KMD5(const Q3CString& a ); |
435 | 437 | ||
436 | /** | 438 | /** |
437 | * Updates the message to be digested. Be sure to add all data | 439 | * Updates the message to be digested. Be sure to add all data |
438 | * before you read the digest. After reading the digest, you | 440 | * before you read the digest. After reading the digest, you |
439 | * can <b>not</b> add more data! | 441 | * can <b>not</b> add more data! |
440 | * | 442 | * |
441 | * @param in message to be added to digest | 443 | * @param in message to be added to digest |
442 | * @param len the length of the given message. | 444 | * @param len the length of the given message. |
443 | */ | 445 | */ |
444 | void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); } | 446 | void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); } |
445 | 447 | ||
446 | /** | 448 | /** |
447 | * @overload | 449 | * @overload |
448 | */ | 450 | */ |
449 | void update(const unsigned char* in, int len = -1); | 451 | void update(const unsigned char* in, int len = -1); |
450 | 452 | ||
451 | /** | 453 | /** |
452 | * @overload | 454 | * @overload |
453 | * | 455 | * |
454 | * @param in message to be added to the digest (QByteArray). | 456 | * @param in message to be added to the digest (QByteArray). |
455 | */ | 457 | */ |
456 | void update(const QByteArray& in ); | 458 | void update(const QByteArray& in ); |
457 | 459 | ||
458 | /** | 460 | /** |
459 | * @overload | 461 | * @overload |
460 | * | 462 | * |
461 | * @param in message to be added to the digest (QByteArray). | 463 | * @param in message to be added to the digest (QByteArray). |
462 | */ | 464 | */ |
463 | void update(const QCString& in ); | 465 | void update(const Q3CString& in ); |
464 | 466 | ||
465 | /** | 467 | /** |
466 | * @overload | 468 | * @overload |
467 | * | 469 | * |
468 | * reads the data from an I/O device, i.e. from a file (QFile). | 470 | * reads the data from an I/O device, i.e. from a file (QFile). |
469 | * | 471 | * |
470 | * NOTE that the file must be open for reading. | 472 | * NOTE that the file must be open for reading. |
471 | * | 473 | * |
472 | * @param file a pointer to FILE as returned by calls like f{d,re}open | 474 | * @param file a pointer to FILE as returned by calls like f{d,re}open |
473 | * | 475 | * |
474 | * @returns false if an error occured during reading. | 476 | * @returns false if an error occured during reading. |
475 | */ | 477 | */ |
476 | bool update(QIODevice& file); | 478 | bool update(QIODevice& file); |
477 | 479 | ||
478 | /** | 480 | /** |
479 | * Calling this function will reset the calculated message digest. | 481 | * Calling this function will reset the calculated message digest. |
480 | * Use this method to perform another message digest calculation | 482 | * Use this method to perform another message digest calculation |
481 | * without recreating the KMD5 object. | 483 | * without recreating the KMD5 object. |
482 | */ | 484 | */ |
483 | void reset(); | 485 | void reset(); |
484 | 486 | ||
485 | /** | 487 | /** |
486 | * @return the raw representation of the digest | 488 | * @return the raw representation of the digest |
487 | */ | 489 | */ |
488 | const Digest& rawDigest (); | 490 | const Digest& rawDigest (); |
489 | 491 | ||
490 | /** | 492 | /** |
491 | * Fills the given array with the binary representation of the | 493 | * Fills the given array with the binary representation of the |
492 | * message digest. | 494 | * message digest. |
493 | * | 495 | * |
494 | * Use this method if you do not want to worry about making | 496 | * Use this method if you do not want to worry about making |
495 | * copy of the digest once you obtain it. | 497 | * copy of the digest once you obtain it. |
496 | * | 498 | * |
497 | * @param bin an array of 16 characters ( char[16] ) | 499 | * @param bin an array of 16 characters ( char[16] ) |
498 | */ | 500 | */ |
499 | void rawDigest( KMD5::Digest& bin ); | 501 | void rawDigest( KMD5::Digest& bin ); |
500 | 502 | ||
501 | /** | 503 | /** |
502 | * Returns the value of the calculated message digest in | 504 | * Returns the value of the calculated message digest in |
503 | * a hexadecimal representation. | 505 | * a hexadecimal representation. |
504 | */ | 506 | */ |
505 | QCString hexDigest (); | 507 | Q3CString hexDigest (); |
506 | 508 | ||
507 | /** | 509 | /** |
508 | * @overload | 510 | * @overload |
509 | */ | 511 | */ |
510 | void hexDigest(QCString&); | 512 | void hexDigest(Q3CString&); |
511 | 513 | ||
512 | /** | 514 | /** |
513 | * Returns the value of the calculated message digest in | 515 | * Returns the value of the calculated message digest in |
514 | * a base64-encoded representation. | 516 | * a base64-encoded representation. |
515 | */ | 517 | */ |
516 | QCString base64Digest (); | 518 | Q3CString base64Digest (); |
517 | 519 | ||
518 | /** | 520 | /** |
519 | * returns true if the calculated digest for the given | 521 | * returns true if the calculated digest for the given |
520 | * message matches the given one. | 522 | * message matches the given one. |
521 | */ | 523 | */ |
522 | bool verify( const KMD5::Digest& digest); | 524 | bool verify( const KMD5::Digest& digest); |
523 | 525 | ||
524 | /** | 526 | /** |
525 | * @overload | 527 | * @overload |
526 | */ | 528 | */ |
527 | bool verify(const QCString&); | 529 | bool verify(const Q3CString&); |
528 | 530 | ||
529 | protected: | 531 | protected: |
530 | /** | 532 | /** |
531 | * Performs the real update work. Note | 533 | * Performs the real update work. Note |
532 | * that length is implied to be 64. | 534 | * that length is implied to be 64. |
533 | */ | 535 | */ |
534 | void transform( const unsigned char buffer[64] ); | 536 | void transform( const unsigned char buffer[64] ); |
535 | 537 | ||
536 | /** | 538 | /** |
537 | * finalizes the digest | 539 | * finalizes the digest |
538 | */ | 540 | */ |
539 | void finalize(); | 541 | void finalize(); |
540 | 542 | ||
541 | private: | 543 | private: |
542 | KMD5(const KMD5& u); | 544 | KMD5(const KMD5& u); |
543 | KMD5& operator=(const KMD5& md); | 545 | KMD5& operator=(const KMD5& md); |
544 | 546 | ||
545 | void init(); | 547 | void init(); |
546 | void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len ); | 548 | void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len ); |
547 | void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len ); | 549 | void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len ); |
548 | 550 | ||
549 | Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n ); | 551 | Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n ); |
550 | Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 552 | Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
551 | Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 553 | Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
552 | Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 554 | Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
553 | Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 555 | Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
554 | void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 556 | void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
555 | Q_UINT32 s, Q_UINT32 ac ); | 557 | Q_UINT32 s, Q_UINT32 ac ); |
556 | void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 558 | void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
557 | Q_UINT32 s, Q_UINT32 ac ); | 559 | Q_UINT32 s, Q_UINT32 ac ); |
558 | void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 560 | void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
559 | Q_UINT32 s, Q_UINT32 ac ); | 561 | Q_UINT32 s, Q_UINT32 ac ); |