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

Side by Side Diff: sdk/lib/convert/base64.dart

Issue 2035473003: Avoid runtime type errors in checked mode for ChunkedConverters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 | « sdk/lib/convert/ascii.dart ('k') | sdk/lib/convert/converter.dart » ('j') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * A [base64](https://tools.ietf.org/html/rfc4648) encoder and decoder. 8 * A [base64](https://tools.ietf.org/html/rfc4648) encoder and decoder.
9 * 9 *
10 * It encodes using the default base64 alphabet, 10 * It encodes using the default base64 alphabet,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Encoder 63 // Encoder
64 // ------------------------------------------------------------------------ 64 // ------------------------------------------------------------------------
65 65
66 /** 66 /**
67 * Base64 and base64url encoding converter. 67 * Base64 and base64url encoding converter.
68 * 68 *
69 * Encodes lists of bytes using base64 or base64url encoding. 69 * Encodes lists of bytes using base64 or base64url encoding.
70 * 70 *
71 * The results are ASCII strings using a restricted alphabet. 71 * The results are ASCII strings using a restricted alphabet.
72 */ 72 */
73 class Base64Encoder extends Converter<List<int>, String> { 73 class Base64Encoder extends Converter<List<int>, String>
74 implements ChunkedConverter<List<int>, String, List<int>, String> {
75
74 final bool _urlSafe; 76 final bool _urlSafe;
75 77
76 const Base64Encoder() : _urlSafe = false; 78 const Base64Encoder() : _urlSafe = false;
77 const Base64Encoder.urlSafe() : _urlSafe = true; 79 const Base64Encoder.urlSafe() : _urlSafe = true;
78 80
79 String convert(List<int> input) { 81 String convert(List<int> input) {
80 if (input.isEmpty) return ""; 82 if (input.isEmpty) return "";
81 var encoder = new _Base64Encoder(_urlSafe); 83 var encoder = new _Base64Encoder(_urlSafe);
82 Uint8List buffer = encoder.encode(input, 0, input.length, true); 84 Uint8List buffer = encoder.encode(input, 0, input.length, true);
83 return new String.fromCharCodes(buffer); 85 return new String.fromCharCodes(buffer);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Decoder 335 // Decoder
334 // ------------------------------------------------------------------------ 336 // ------------------------------------------------------------------------
335 337
336 /** 338 /**
337 * Decoder for base64 encoded data. 339 * Decoder for base64 encoded data.
338 * 340 *
339 * This decoder accepts both base64 and base64url ("url-safe") encodings. 341 * This decoder accepts both base64 and base64url ("url-safe") encodings.
340 * 342 *
341 * The encoding is required to be properly padded. 343 * The encoding is required to be properly padded.
342 */ 344 */
343 class Base64Decoder extends Converter<String, List<int>> { 345 class Base64Decoder extends Converter<String, List<int>>
346 implements ChunkedConverter<String, List<int>, String, List<int>> {
344 347
345 const Base64Decoder(); 348 const Base64Decoder();
346 349
347 List<int> convert(String input, [int start = 0, int end]) { 350 List<int> convert(String input, [int start = 0, int end]) {
348 end = RangeError.checkValidRange(start, end, input.length); 351 end = RangeError.checkValidRange(start, end, input.length);
349 if (start == end) return new Uint8List(0); 352 if (start == end) return new Uint8List(0);
350 var decoder = new _Base64Decoder(); 353 var decoder = new _Base64Decoder();
351 Uint8List buffer = decoder.decode(input, start, end); 354 Uint8List buffer = decoder.decode(input, start, end);
352 decoder.close(input, end); 355 decoder.close(input, end);
353 return buffer; 356 return buffer;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 end = RangeError.checkValidRange(start, end, string.length); 744 end = RangeError.checkValidRange(start, end, string.length);
742 if (start == end) return; 745 if (start == end) return;
743 Uint8List buffer = _decoder.decode(string, start, end); 746 Uint8List buffer = _decoder.decode(string, start, end);
744 if (buffer != null) _sink.add(buffer); 747 if (buffer != null) _sink.add(buffer);
745 if (isLast) { 748 if (isLast) {
746 _decoder.close(string, end); 749 _decoder.close(string, end);
747 _sink.close(); 750 _sink.close();
748 } 751 }
749 } 752 }
750 } 753 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/ascii.dart ('k') | sdk/lib/convert/converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698