Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: lib/src/base64.dart

Issue 1335713003: Make base64 decoding return a Uint8List. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « .gitignore ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of crypto; 5 part of crypto;
6 6
7 const Base64Codec BASE64 = const Base64Codec(); 7 const Base64Codec BASE64 = const Base64Codec();
8 8
9 const List<int> _decodeTable = 9 const List<int> _decodeTable =
10 const [ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, 10 const [ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2,
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 class Base64Decoder extends Converter<String, List<int>> { 271 class Base64Decoder extends Converter<String, List<int>> {
272 272
273 /** 273 /**
274 * Instantiates a new [Base64Decoder] 274 * Instantiates a new [Base64Decoder]
275 */ 275 */
276 const Base64Decoder(); 276 const Base64Decoder();
277 277
278 List<int> convert(String input) { 278 List<int> convert(String input) {
279 int length = input.length; 279 int length = input.length;
280 if (length == 0) { 280 if (length == 0) {
281 return new List<int>(0); 281 return new Uint8List<int>(0);
282 } 282 }
283 283
284 int normalLength = 0; 284 int normalLength = 0;
285 int i = 0; 285 int i = 0;
286 // Count '\r', '\n' and illegal characters, check if 286 // Count '\r', '\n' and illegal characters, check if
287 // '/', '+' / '-', '_' are used consistently, for illegal characters, 287 // '/', '+' / '-', '_' are used consistently, for illegal characters,
288 // throw an exception. 288 // throw an exception.
289 289
290 while (i < length) { 290 while (i < length) {
291 int codeUnit = input.codeUnitAt(i); 291 int codeUnit = input.codeUnitAt(i);
(...skipping 30 matching lines...) Expand all
322 padLength++; 322 padLength++;
323 i -= 2; 323 i -= 2;
324 } else if (_decodeTable[currentCodeUnit] > 0) { 324 } else if (_decodeTable[currentCodeUnit] > 0) {
325 break; 325 break;
326 } else if (currentCodeUnit == _PAD_BYTES[0]) { 326 } else if (currentCodeUnit == _PAD_BYTES[0]) {
327 padLength++; 327 padLength++;
328 } 328 }
329 i--; 329 i--;
330 } 330 }
331 int outputLength = ((normalLength * 6) >> 3) - padLength; 331 int outputLength = ((normalLength * 6) >> 3) - padLength;
332 List<int> out = new List<int>(outputLength); 332 List<int> out = new Uint8List<int>(outputLength);
333 333
334 for (int i = 0, o = 0; o < outputLength; ) { 334 for (int i = 0, o = 0; o < outputLength; ) {
335 // Accumulate 4 valid 6 bit Base 64 characters into an int. 335 // Accumulate 4 valid 6 bit Base 64 characters into an int.
336 int x = 0; 336 int x = 0;
337 for (int j = 4; j > 0; ) { 337 for (int j = 4; j > 0; ) {
338 int c = _decodeTable[input.codeUnitAt(i++)]; 338 int c = _decodeTable[input.codeUnitAt(i++)];
339 if (c >= 0) { 339 if (c >= 0) {
340 x = ((x << 6) & 0x00FFFFFF) | c; 340 x = ((x << 6) & 0x00FFFFFF) | c;
341 j--; 341 j--;
342 } 342 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 390
391 void close() { 391 void close() {
392 if (_unconverted.isNotEmpty) { 392 if (_unconverted.isNotEmpty) {
393 _outSink.add(_decoder.convert(_unconverted)); 393 _outSink.add(_decoder.convert(_unconverted));
394 } 394 }
395 _outSink.close(); 395 _outSink.close();
396 } 396 }
397 } 397 }
398 398
399 399
OLDNEW
« no previous file with comments | « .gitignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698