| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:convert'; | |
| 6 | |
| 7 import 'base64/decoder.dart'; | |
| 8 import 'base64/encoder.dart'; | |
| 9 | |
| 10 /// This is deprecated. | |
| 11 /// | |
| 12 /// Use the `BASE64` constant in `dart:convert` instead. | |
| 13 @Deprecated("Will be removed in crypto 1.0.0.") | |
| 14 const Base64Codec BASE64 = const Base64Codec(); | |
| 15 | |
| 16 /// This is deprecated. | |
| 17 /// | |
| 18 /// Use the `Base64Codec` class in `dart:convert` instead. | |
| 19 @Deprecated("Will be removed in crypto 1.0.0.") | |
| 20 class Base64Codec extends Codec<List<int>, String> { | |
| 21 final bool _urlSafe; | |
| 22 final bool _addLineSeparator; | |
| 23 final bool _encodePaddingCharacter; | |
| 24 | |
| 25 /// Creates a new [Base64Codec]. | |
| 26 /// | |
| 27 /// The default [BASE64] codec will be good enough for most cases. A new codec | |
| 28 /// only needs to be instantiated when you want to do multiple conversions | |
| 29 /// with the same configuration. | |
| 30 /// | |
| 31 /// If [urlSafe] is `true`, a URL-safe alphabet will be used when encoding. | |
| 32 /// Specifically, the characters `-` and `_` will be used instead of `+` and | |
| 33 /// `/`. | |
| 34 /// | |
| 35 /// If [addLineSeparator] is `true`, `\r\n` line separators will be added | |
| 36 /// every 76 characters when encoding. | |
| 37 /// | |
| 38 /// If [encodePaddingCharacter] is `true`, the padding character `=` will be | |
| 39 /// written as `%3D` when encoding. | |
| 40 const Base64Codec( | |
| 41 {bool urlSafe: false, | |
| 42 bool addLineSeparator: false, | |
| 43 bool encodePaddingCharacter: false}) | |
| 44 : _urlSafe = urlSafe, | |
| 45 _addLineSeparator = addLineSeparator, | |
| 46 _encodePaddingCharacter = encodePaddingCharacter; | |
| 47 | |
| 48 String get name => "base64"; | |
| 49 | |
| 50 /// Encodes [bytes] into a Base64 string. | |
| 51 /// | |
| 52 /// If [urlSafe] is `true`, a URL-safe alphabet will be used when encoding. | |
| 53 /// Specifically, the characters `-` and `_` will be used instead of `+` and | |
| 54 /// `/`. | |
| 55 /// | |
| 56 /// If [addLineSeparator] is `true`, `\r\n` line separators will be added | |
| 57 /// every 76 characters when encoding. | |
| 58 /// | |
| 59 /// If [encodePaddingCharacter] is `true`, the padding character `=` will be | |
| 60 /// written as `%3D` when encoding. | |
| 61 /// | |
| 62 /// Any flags passed to this method take precedence over the flags passed to | |
| 63 /// the codec itself. | |
| 64 String encode(List<int> bytes, | |
| 65 {bool urlSafe, bool addLineSeparator, bool encodePaddingCharacter}) { | |
| 66 if (urlSafe == null) urlSafe = _urlSafe; | |
| 67 if (addLineSeparator == null) addLineSeparator = _addLineSeparator; | |
| 68 if (encodePaddingCharacter == null) { | |
| 69 encodePaddingCharacter = _encodePaddingCharacter; | |
| 70 } | |
| 71 | |
| 72 return new Base64Encoder( | |
| 73 urlSafe: urlSafe, | |
| 74 addLineSeparator: addLineSeparator, | |
| 75 encodePaddingCharacter: encodePaddingCharacter).convert(bytes); | |
| 76 } | |
| 77 | |
| 78 Base64Encoder get encoder => new Base64Encoder( | |
| 79 urlSafe: _urlSafe, | |
| 80 addLineSeparator: _addLineSeparator, | |
| 81 encodePaddingCharacter: _encodePaddingCharacter); | |
| 82 | |
| 83 Base64Decoder get decoder => const Base64Decoder(); | |
| 84 } | |
| OLD | NEW |