OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> | 2 Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> |
3 Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> | 3 Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> |
4 Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 4 Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
5 Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 5 Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU Lesser General Public License (LGPL) | 8 it under the terms of the GNU Lesser General Public License (LGPL) |
9 version 2 as published by the Free Software Foundation. | 9 version 2 as published by the Free Software Foundation. |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } else if (charactersPolicy == Base64FailOnInvalidCharacter || (characte
rsPolicy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch))) | 175 } else if (charactersPolicy == Base64FailOnInvalidCharacter || (characte
rsPolicy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch))) |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 if (!outLength) | 179 if (!outLength) |
180 return !sawEqualsSign; | 180 return !sawEqualsSign; |
181 | 181 |
182 // Valid data is (n * 4 + [0,2,3]) characters long. | 182 // Valid data is (n * 4 + [0,2,3]) characters long. |
183 if ((outLength % 4) == 1) | 183 if ((outLength % 4) == 1) |
184 return false; | 184 return false; |
185 | 185 |
186 // 4-byte to 3-byte conversion | 186 // 4-byte to 3-byte conversion |
187 outLength -= (outLength + 3) / 4; | 187 outLength -= (outLength + 3) / 4; |
188 if (!outLength) | 188 if (!outLength) |
189 return false; | 189 return false; |
190 | 190 |
191 unsigned sidx = 0; | 191 unsigned sidx = 0; |
192 unsigned didx = 0; | 192 unsigned didx = 0; |
193 if (outLength > 1) { | 193 if (outLength > 1) { |
194 while (didx < outLength - 2) { | 194 while (didx < outLength - 2) { |
195 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003)
); | 195 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003)
); |
(...skipping 24 matching lines...) Expand all Loading... |
220 bool base64Decode(const String& in, Vector<char>& out, Base64InvalidCharactersPo
licy charactersPolicy, Base64PaddingValidationPolicy paddingPolicy) | 220 bool base64Decode(const String& in, Vector<char>& out, Base64InvalidCharactersPo
licy charactersPolicy, Base64PaddingValidationPolicy paddingPolicy) |
221 { | 221 { |
222 if (in.isEmpty()) | 222 if (in.isEmpty()) |
223 return base64DecodeInternal<LChar>(0, 0, out, charactersPolicy, paddingP
olicy); | 223 return base64DecodeInternal<LChar>(0, 0, out, charactersPolicy, paddingP
olicy); |
224 if (in.is8Bit()) | 224 if (in.is8Bit()) |
225 return base64DecodeInternal<LChar>(in.characters8(), in.length(), out, c
haractersPolicy, paddingPolicy); | 225 return base64DecodeInternal<LChar>(in.characters8(), in.length(), out, c
haractersPolicy, paddingPolicy); |
226 return base64DecodeInternal<UChar>(in.characters16(), in.length(), out, char
actersPolicy, paddingPolicy); | 226 return base64DecodeInternal<UChar>(in.characters16(), in.length(), out, char
actersPolicy, paddingPolicy); |
227 } | 227 } |
228 | 228 |
229 } // namespace WTF | 229 } // namespace WTF |
OLD | NEW |